Synced Light Toggle
Toggle a light on or off globally for all players.
Category: Networking Systems
UdonSharp Script
using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;
public class SyncedLightToggle : UdonSharpBehaviour
{
public Light targetLight;
[UdonSynced] private bool isOn = true;
private void Start()
{
ApplyState();
}
public override void Interact()
{
VRCPlayerApi localPlayer = Networking.LocalPlayer;
if (localPlayer == null || targetLight == null) return;
Networking.SetOwner(localPlayer, gameObject);
isOn = !isOn;
ApplyState();
RequestSerialization();
}
public override void OnDeserialization()
{
ApplyState();
}
private void ApplyState()
{
if (targetLight == null) return;
targetLight.enabled = isOn;
}
}
Setup
- Add script to a button object with
VRC_Interactable. - Assign scene light to
targetLight. - Test with two players to confirm sync.
Extra Tips and Troubleshooting
Tips and Tricks
- Use this for simple day/night or event mode controls.
- Pair with emissive material state for clearer visual feedback.
Troubleshooting
- If light state differs across players, verify serialization and ownership assignment.
Related Content
Prefab Setup Notes
Import the prefab or script into a throwaway test scene before adding it to a live world. Confirm inspector references, ownership behavior, sync, triggers, UI hooks, and audio or object links before moving it into the production scene.
Testing Checklist
- Test once as a local player and again with a second client or late joiner if the behavior can affect more than one player.
- Confirm ownership, sync, trigger zones, UI references, and audio or object references are assigned intentionally.
- Check desktop and VR interaction distance so players can actually use the feature in context.
- Keep a backup of the scene before changing prefabs, UdonBehaviours, or serialized references.
