diff --git a/Assets/UdonSharp/Editor/Editors/UdonSharpBehaviourEditor.cs b/Assets/UdonSharp/Editor/Editors/UdonSharpBehaviourEditor.cs index 5b252bfd..90a13a11 100644 --- a/Assets/UdonSharp/Editor/Editors/UdonSharpBehaviourEditor.cs +++ b/Assets/UdonSharp/Editor/Editors/UdonSharpBehaviourEditor.cs @@ -378,10 +378,13 @@ void OnUndoRedo() if (customEditorType != null) // Only do the undo copying on things with a custom inspector { - UdonSharpEditorUtility.CopyProxyToUdon(inspectorTarget, ProxySerializationPolicy.All); - - if (PrefabUtility.IsPartOfPrefabInstance(behaviour)) - PrefabUtility.RecordPrefabInstancePropertyModifications(behaviour); + if ((bool)typeof(UdonSharpBehaviour).GetField("_isValidForAutoCopy", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(inspectorTarget)) + { + UdonSharpEditorUtility.CopyProxyToUdon(inspectorTarget, ProxySerializationPolicy.All); + + if (PrefabUtility.IsPartOfPrefabInstance(behaviour)) + PrefabUtility.RecordPrefabInstancePropertyModifications(behaviour); + } } } } @@ -406,6 +409,8 @@ void CleanupProxy() } } } + + static FieldInfo _autoCopyValidField = null; public override void OnInspectorGUI() { @@ -445,6 +450,11 @@ public override void OnInspectorGUI() UdonSharpBehaviour inspectorTarget = UdonSharpEditorUtility.GetProxyBehaviour(behaviour, ProxySerializationPolicy.All); inspectorTarget.enabled = false; + if (_autoCopyValidField == null) + _autoCopyValidField = typeof(UdonSharpBehaviour).GetField("_isValidForAutoCopy", BindingFlags.NonPublic | BindingFlags.Instance); + + _autoCopyValidField.SetValue(inspectorTarget, true); + Editor.CreateCachedEditorWithContext(inspectorTarget, this, customEditorType, ref baseEditor); currentProxyBehaviour = inspectorTarget; diff --git a/Assets/UdonSharp/Scripts/UdonSharpBehaviour.cs b/Assets/UdonSharp/Scripts/UdonSharpBehaviour.cs index 7190d33d..65035027 100644 --- a/Assets/UdonSharp/Scripts/UdonSharpBehaviour.cs +++ b/Assets/UdonSharp/Scripts/UdonSharpBehaviour.cs @@ -145,6 +145,9 @@ void ISerializationCallbackReceiver.OnAfterDeserialize() [OdinSerialize] private IUdonBehaviour _backingUdonBehaviour; + + [SerializeField] + private bool _isValidForAutoCopy = false; #endif } }