From 150f30f56c3148a9b6b42ff7af033976f4ce8bf5 Mon Sep 17 00:00:00 2001 From: Luis Gonzalez Date: Thu, 13 Aug 2026 23:03:15 -0700 Subject: [PATCH] =?UTF-8?q?Fix:=20PixelArtDevControls=20is=20opt-in=20?= =?UTF-8?q?=E2=80=94=20it=20was=20running=20OnGUI=20in=20Game.unity=20ever?= =?UTF-8?q?y=20frame?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The editor-only pixel-art tuner self-spawned via [RuntimeInitializeOnLoadMethod] + DontDestroyOnLoad into EVERY scene, not just DevSandbox, and its OnGUI draws the toggle button on every IMGUI pass BEFORE the `!_open` early-out. IMGUI dispatches at least Layout+Repaint per frame, so it allocated continuously during normal gameplay — it is a MonoBehaviour, so an ECS system-toggle sweep never touched it, and it dominated this session's allocation profiling until it was found. Now gated behind an EditorPrefs opt-in with a checked menu toggle, mirroring `ProjectM/Boot Into Menu (Editor)`. Off by default. Separately: because the object carries HideFlags.DontSave it SURVIVES play-mode exit while the static _instance does not, so the old code leaked one instance per domain reload — two live strays were found and cleared in the editor. Co-Authored-By: Claude Opus 5 (1M context) --- .../Client/Debug/PixelArtDevControls.cs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Assets/_Project/Scripts/Client/Debug/PixelArtDevControls.cs b/Assets/_Project/Scripts/Client/Debug/PixelArtDevControls.cs index a10bac7af..e110589d0 100644 --- a/Assets/_Project/Scripts/Client/Debug/PixelArtDevControls.cs +++ b/Assets/_Project/Scripts/Client/Debug/PixelArtDevControls.cs @@ -21,11 +21,33 @@ namespace ProjectM.Client static PixelArtDevControls _instance; + /// + /// OPT-IN EditorPref, mirroring `ProjectM/Boot Into Menu (Editor)`. This used to self-spawn into EVERY + /// scene — Game.unity included, not just DevSandbox — and draws its toggle button on + /// every IMGUI pass BEFORE the `!_open` early-out. IMGUI dispatches at least Layout+Repaint per frame, + /// so it allocated continuously during normal gameplay and dominated allocation profiling until it was + /// found on 2026-08-13. Off by default; enable from the menu when you actually want to tune the look. + /// + const string EnabledPref = "ProjectM.PixelArtDevControls.Enabled"; + const string MenuPath = "ProjectM/Pixel Art Dev Controls (Editor)"; + + [MenuItem(MenuPath)] + static void ToggleEnabled() => EditorPrefs.SetBool(EnabledPref, !EditorPrefs.GetBool(EnabledPref, false)); + + [MenuItem(MenuPath, true)] + static bool ToggleEnabledValidate() + { + Menu.SetChecked(MenuPath, EditorPrefs.GetBool(EnabledPref, false)); + return true; + } + [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)] static void Bootstrap() { if (_instance != null) return; + if (!EditorPrefs.GetBool(EnabledPref, false)) + return; // opt-in only — see EnabledPref var go = new GameObject("~PixelArtDevControls") { hideFlags = HideFlags.HideAndDontSave }; DontDestroyOnLoad(go); _instance = go.AddComponent();