Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update NodeEditor.cs
I initially found out about this through
https://docs.unity3d.com/ScriptReference/Editor.html 
specifically these two comments:

```csharp
// Update the serializedProperty - always do this in the beginning of OnInspectorGUI.
        serializedObject.Update ();
...
// Apply changes to the serializedProperty - always do this in the end of OnInspectorGUI.
        serializedObject.ApplyModifiedProperties ();
```

I'm assuming, although I don't know for sure, that since OnBodyGUI displays the serialize objects in the custom inspector, that it must follow the same rules as well. Either way these lines of code solve for me the glitch: pressing undo while typing and getting a disconnect between the node and the inspector.
  • Loading branch information
phoenixanimations committed Aug 27, 2018
1 parent 83acd16 commit ffc061f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Scripts/Editor/NodeEditor.cs
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
Expand Down Expand Up @@ -43,6 +43,10 @@ public class NodeEditor : XNodeEditor.Internal.NodeEditorBase<NodeEditor, NodeEd

/// <summary> Draws standard field editors for all public fields </summary>
public virtual void OnBodyGUI() {
// Unity specifically requires this to save/update any serial object.
// serializedObject.Update(); must go at the start of an inspector gui, and
// serializedObject.ApplyModifiedProperties(); goes at the end.
serializedObject.Update();
string[] excludes = { "m_Script", "graph", "position", "ports" };
portPositions = new Dictionary<XNode.NodePort, Vector2>();

Expand All @@ -54,6 +58,7 @@ public class NodeEditor : XNodeEditor.Internal.NodeEditorBase<NodeEditor, NodeEd
if (excludes.Contains(iterator.name)) continue;
NodeEditorGUILayout.PropertyField(iterator, true);
}
serializedObject.ApplyModifiedProperties();
}

public virtual int GetWidth() {
Expand Down Expand Up @@ -93,4 +98,5 @@ public class CustomNodeEditorAttribute : Attribute,
}
}
}
}

}

0 comments on commit ffc061f

Please sign in to comment.