From 8a9f9eb96a43de753da46f7c95a9d45f0b0c3e33 Mon Sep 17 00:00:00 2001 From: Nikita Date: Thu, 26 Feb 2026 03:52:10 +0200 Subject: [PATCH] fix: Track and correctly destroy created editors. Track and destroy editors created during entity inspection. Prevent Unity errors on subsequent editor draw calls. --- .../Assets/Arch.Unity/Editor/EntityEditor.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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 +}