Admin-Only Toggle (Whitelist)

This script lets only approved player IDs toggle a synced object.

Category: Networking Systems

Important

This is a simple world-level control pattern, not a secure moderation system. Keep admin lists maintained and test in live instances.

UdonSharp Script

using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;

public class AdminOnlyToggle : UdonSharpBehaviour
{
    [Header("Object to toggle globally")]
    public GameObject targetObject;

    [Header("Allowed player IDs")]
    public int[] adminPlayerIds;

    [UdonSynced] private bool isEnabled = true;

    private void Start()
    {
        ApplyState();
    }

    public override void Interact()
    {
        VRCPlayerApi localPlayer = Networking.LocalPlayer;
        if (localPlayer == null || !IsAdmin(localPlayer.playerId) || targetObject == null)
        {
            return;
        }

        Networking.SetOwner(localPlayer, gameObject);
        isEnabled = !isEnabled;
        ApplyState();
        RequestSerialization();
    }

    public override void OnDeserialization()
    {
        ApplyState();
    }

    private bool IsAdmin(int playerId)
    {
        if (adminPlayerIds == null)
        {
            return false;
        }

        for (int i = 0; i < adminPlayerIds.Length; i++)
        {
            if (adminPlayerIds[i] == playerId)
            {
                return true;
            }
        }
        return false;
    }

    private void ApplyState()
    {
        targetObject.SetActive(isEnabled);
    }
}

License:

Unity Setup

  1. Add this script to your admin switch object.
  2. Add VRC_Interactable.
  3. Assign targetObject.
  4. Fill adminPlayerIds with players you want to allow.
  5. Test with at least one non-admin account.

Notes

  • playerId values are per-instance and can change each session.
  • For production admin flows, pair this with a trusted runtime assignment method.

Extra Tips and Troubleshooting

Tips and Tricks

  • Include an on-screen status label so users know why interaction is blocked.
  • Keep admin controls grouped in a maintenance area.

Troubleshooting

  • If admins cannot toggle, verify current player IDs for that session.

Related Content

Official References