diff --git a/src/Arch.Unity/Assets/Arch.Unity/Editor/EntityEditor.cs b/src/Arch.Unity/Assets/Arch.Unity/Editor/EntityEditor.cs index 19945b0..ae47600 100644 --- a/src/Arch.Unity/Assets/Arch.Unity/Editor/EntityEditor.cs +++ b/src/Arch.Unity/Assets/Arch.Unity/Editor/EntityEditor.cs @@ -22,6 +22,10 @@ void OnEnable() void OnDisable() { EditorApplication.update -= Repaint; + foreach (var (_, editor) in editorCache) + { + DestroyImmediate(editor); + } editorCache.Clear(); } @@ -57,7 +61,11 @@ public override void OnInspectorGUI() { if (component is UnityEngine.Component c) { - if (!editorCache.TryGetValue(c, out var editor)) editor = CreateEditor(c); + if (!editorCache.TryGetValue(c, out var editor)) + { + editor = CreateEditor(c); + editorCache.Add(c, editor); + } if (editor != null) editor.OnInspectorGUI(); } else @@ -241,4 +249,4 @@ static void DrawMembers(object target, string rootPath, int depth) } } } -} \ No newline at end of file +}