Instance Master Toggle
Allow only the current instance master to toggle a shared object.
Category: Networking Systems
UdonSharp Script
using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;
public class InstanceMasterToggle : UdonSharpBehaviour
{
public GameObject targetObject;
[UdonSynced] private bool isVisible = true;
private void Start()
{
ApplyState();
}
public override void Interact()
{
VRCPlayerApi localPlayer = Networking.LocalPlayer;
if (localPlayer == null || targetObject == null) return;
if (!Networking.IsMaster) return;
Networking.SetOwner(localPlayer, gameObject);
isVisible = !isVisible;
ApplyState();
RequestSerialization();
}
public override void OnDeserialization()
{
ApplyState();
}
private void ApplyState()
{
targetObject.SetActive(isVisible);
}
}
Setup
- Add script to interactable button.
- Assign
targetObject. - Test with two users and switch master to verify behavior.
Extra Tips and Troubleshooting
Tips and Tricks
- Use master-only controls for lightweight live operations.
- Add visible hint text that only master can use the control.
Troubleshooting
- If interaction fails, test with current master and verify master transfer behavior.
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.
