Skip to content

StrangeToggle

Fynn9563 edited this page Jan 28, 2026 · 1 revision

StrangeToggle

StrangeToggle is an interactive component that creates toggleable objects with optional state persistence.

Video Tutorial

Coming soon - video tutorial placeholder

Overview

Use StrangeToggle for:

  • Light switches
  • Doors and gates
  • Interactive displays
  • Any on/off interaction

Properties

Core Settings

Property Type Description
persistenceID string Unique identifier for state saving
usePersistence bool Enable/disable state saving
defaultOn bool Starting state (when no saved state)
sceneHub StrangeHub Reference to the scene's hub

Visual Targets

Property Type Description
toggleObjects GameObject[] Objects to activate/deactivate
emissionRenderers Renderer[] Renderers with emission to toggle
emissionOnColor Color Emission color when ON
emissionOffColor Color Emission color when OFF
animators Animator[] Animators to sync with toggle state
animatorBoolParam string Bool parameter name to set

Audio

Property Type Description
soundSource AudioSource AudioSource for feedback sounds
onSound AudioClip Sound when toggled ON
offSound AudioClip Sound when toggled OFF

Public Methods

Interact()

Called by VRChat when a player interacts with the object.

// Automatically called by VRChat
public override void Interact()
{
    Toggle();
}

Toggle()

Toggles between ON and OFF states.

// Can be called from other scripts
toggle.Toggle();

UpdateVisuals()

Applies the current state to all visual targets.

// Force visual refresh
toggle.UpdateVisuals();

RefreshPersistence()

Loads saved state from the hub. Called on player join.

// Restore saved state
toggle.RefreshPersistence();

How It Works

On Toggle

  1. State flips (ON → OFF or OFF → ON)
  2. If persistence enabled, saves to hub
  3. Plays appropriate sound (if configured)
  4. Updates all visuals

Visual Updates

For each target type:

Toggle Objects:

  • SetActive(state) on each GameObject

Emission Renderers:

  • Sets _EmissionColor to on/off color
  • Calls DynamicGI.SetEmissive() for lighting update

Animators:

  • Sets bool parameter to current state

Scene View Gizmos

In the Unity editor, StrangeToggle displays:

  • Yellow sphere at toggle position
  • Cyan line to StrangeHub
  • White lines to toggle objects
  • Magenta lines to emission renderers
  • Green lines to animators

This visualization helps verify connections without selecting the object.

Setup Examples

Basic Light Switch

persistenceID: "room_light"
usePersistence: true
defaultOn: false
toggleObjects: [LightObject]
onSound: switch_click.wav
offSound: switch_click.wav

Neon Sign with Glow

persistenceID: "neon_sign"
usePersistence: true
defaultOn: true
emissionRenderers: [SignRenderer]
emissionOnColor: (1, 0, 0.5, 1)  // Pink glow
emissionOffColor: (0, 0, 0, 1)   // No glow
onSound: buzz_on.wav
offSound: buzz_off.wav

Animated Door

persistenceID: "front_door"
usePersistence: false
defaultOn: false
animators: [DoorAnimator]
animatorBoolParam: "IsOpen"
toggleObjects: [DoorCollider]  // Disable collider when open
onSound: door_open.wav
offSound: door_close.wav

Complex Multi-Target

persistenceID: "control_panel"
usePersistence: true
defaultOn: false
toggleObjects: [Light1, Light2, FanObject]
emissionRenderers: [ButtonRenderer, IndicatorRenderer]
emissionOnColor: (0, 1, 0, 1)   // Green
emissionOffColor: (1, 0, 0, 1)  // Red
animators: [PanelAnimator]
animatorBoolParam: "Activated"
onSound: panel_activate.wav
offSound: panel_deactivate.wav

Best Practices

Persistence IDs

  • Use descriptive names: kitchen_light, garage_door
  • Keep unique across the entire world
  • Don't change after publishing (breaks saved states)

Performance

  • Limit toggle objects to necessary items
  • Use animators for complex state changes
  • Keep sounds short (< 1 second)

Audio

  • Set AudioSource to 3D spatial blend for positional audio
  • Keep volume reasonable
  • Test sound distances in VRChat

Animator Setup

  • Create a simple bool parameter
  • Make transitions with conditions
  • Avoid complex state machines for toggles

Troubleshooting

Toggle not responding

  • Verify object has a collider for interaction
  • Check that StrangeHub is assigned
  • Ensure the object is on an interactable layer

State not persisting

  • Check usePersistence is enabled
  • Verify persistenceID is not empty
  • Confirm StrangeHub reference is set

Emission not changing

  • Verify material uses Standard shader or has _EmissionColor
  • Check emission is enabled on the material
  • Ensure renderer is in the emissionRenderers array

Sound not playing

  • Check AudioSource is assigned
  • Verify AudioClips are assigned
  • Test AudioSource plays in isolation

Clone this wiki locally