Skip to content

Instantly share code, notes, and snippets.

@Vavassor
Created November 8, 2025 00:15
Show Gist options
  • Select an option

  • Save Vavassor/3ec3850234f4678d744491e6534508ad to your computer and use it in GitHub Desktop.

Select an option

Save Vavassor/3ec3850234f4678d744491e6534508ad to your computer and use it in GitHub Desktop.
VRChat U# example for setting a singleton manager reference on many objects, using a button.
using UdonSharpEditor;
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(PropManager)), CanEditMultipleObjects]
public class PropManagerEditor : UnityEditor.Editor
{
public override void OnInspectorGUI()
{
if (UdonSharpGUI.DrawDefaultUdonSharpBehaviourHeader(target)) return;
var propManager = (PropManager)target;
if (GUILayout.Button("Add Manager to Props"))
{
var props = FindObjectsOfType<Prop>(true);
foreach (var propComponent in props)
{
var prop = new SerializedObject(propComponent);
prop.FindProperty("propManager").objectReferenceValue = propManager;
prop.ApplyModifiedProperties();
}
}
GUILayout.Space();
// DrawDefaultInspector adds all the other fields. So you don't need to customize
// everything in the inspector!
DrawDefaultInspector();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment