diff --git a/Scripts/Editor/NodeEditorBase.cs b/Scripts/Editor/NodeEditorBase.cs index 67d4833..471fea0 100644 --- a/Scripts/Editor/NodeEditorBase.cs +++ b/Scripts/Editor/NodeEditorBase.cs @@ -10,6 +10,7 @@ namespace XNodeInternal { public class NodeEditorBase where A : Attribute, NodeEditorBase.INodeEditorAttrib where T : NodeEditorBase where K : ScriptableObject { /// Custom editors defined with [CustomNodeEditor] private static Dictionary editors; + private static Dictionary serializeds; public K target; public SerializedObject serializedObject; @@ -18,10 +19,17 @@ namespace XNodeInternal { Type type = target.GetType(); T editor = GetEditor(type); editor.target = target; - editor.serializedObject = new SerializedObject(target); + editor.serializedObject = GetSerialized(target); return editor; } + private static SerializedObject GetSerialized(K target) { + if (target == null) return null; + if (serializeds == null) serializeds = new Dictionary(); + if (!serializeds.ContainsKey(target)) serializeds.Add(target, new SerializedObject(target)); + return serializeds[target]; + } + private static T GetEditor(Type type) { if (type == null) return null; if (editors == null) CacheCustomEditors();