I have a project I’m close to completing with four separate scenes - three levels and a main menu (index 0). My main menu, pause menu and door controller (loads specified scene on trigger) are all working nicely, but I have one hitch - the ‘main menu’ button in my pause menu is giving me hell.
Currently I’m using scene management build index to return to scene 0 on click, but I’m getting an ungodly amount of null ref exceptions thanks to the game objects which persist between scenes after the main menu.
Some of these objects are instantiated when scene 1 is loaded from the main menu, others exist in scene 1 and use DontDestroyOnLoad & gameObject array to ensure no more than one instance exists in a scene at a time (ex countdown timer). I’m aware this isn’t the greatest practice.
What would be the best/most efficient way to disable these persistent objects when the pause menu on click logic is called? I’ve tried setting an array of game objects to disabled (SetActive(false)), but even though these components are inactive the code attached to them is still throwing null ref errors.
I’m (foolishly) not using object pooling to control instantiated/persistent objects and unfortunately I don’t have enough time before my deadline to start. Short of sticking disabled instances of these persistent game objects in my menu scene how can I tackle this?
I’ll add any relevant pre-existing code if necessary in a few hours, but I’d mostly just like a logic walkthrough/workaround.