From 49e28530125b3bb2824b83ce93b6f8a516b389f7 Mon Sep 17 00:00:00 2001 From: Skilvin Date: Fri, 5 Jun 2026 13:54:31 +0200 Subject: [PATCH] Fix startup NRE on WorldBox 0.51.2: resilient power-tab lookup GetTab() now falls back to finding the PowersTab by object name when the hard-coded UI hierarchy path no longer matches (0.51.1+), and the WrappedPowersTab constructor guards against a null tab to avoid an NRE during vanilla-tab reconstruction. Co-Authored-By: Claude Opus 4.8 --- general/PowerButtonCreator.cs | 15 ++++++++++++++- general/ui/tab/WrappedPowersTab.cs | 16 ++++++++++++---- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/general/PowerButtonCreator.cs b/general/PowerButtonCreator.cs index ff3e34a5..1f863b9d 100644 --- a/general/PowerButtonCreator.cs +++ b/general/PowerButtonCreator.cs @@ -278,10 +278,23 @@ void toggleOption(string pPower) public static PowersTab GetTab(string pId) { if (string.IsNullOrEmpty(pId)) return null; + + // Fast path (valid up to 0.51.0): hard-coded UI hierarchy lookup. Transform tabTransform = CanvasMain.instance.canvas_ui.transform.Find( $"CanvasBottom/BottomElements/BottomElementsMover/CanvasScrollView/Scroll View/Viewport/Content/Power Tabs/{pId}"); + if (tabTransform != null) + { + var found = tabTransform.GetComponent(); + if (found != null) return found; + } + + // Fallback (0.51.1+): the hierarchy moved. Locate the tab by its object name. + foreach (var tab in Resources.FindObjectsOfTypeAll()) + { + if (tab != null && tab.name == pId) return tab; + } - return tabTransform == null ? null : tabTransform.GetComponent(); + return null; } /// diff --git a/general/ui/tab/WrappedPowersTab.cs b/general/ui/tab/WrappedPowersTab.cs index 35bb9f48..a40f2207 100644 --- a/general/ui/tab/WrappedPowersTab.cs +++ b/general/ui/tab/WrappedPowersTab.cs @@ -25,15 +25,23 @@ public WrappedPowersTab(PowersTab pPowersTab) { Tab = pPowersTab; - Modifiable = !PowerTabNames.GetNames().Contains(Tab.name); - ButtonGroups = new(); CustomRectGroups = new(); - AddGroup("Default"); - _inactive_lines = new(); _active_lines = new(); + + if (Tab == null) + { + // Tab not found (e.g. hierarchy changed in a newer WorldBox build): + // don't NRE, just leave this wrapper inert. + Modifiable = false; + return; + } + + Modifiable = !PowerTabNames.GetNames().Contains(Tab.name); + + AddGroup("Default"); } internal void RecordLine(GameObject line)