- Home /
Button OnClick() Scripts lose assignments on scene reload
In my game I have a Menu scene with various buttons. In my game, when you die, it sends you back to the menu and you should be able to use the buttons to change the game settings (such as number of enemies). However, once it loads back into the menu scene after the game scene, none of the buttons do anything. Upon further inspection, I realized that the functions they had been assigned in the inspector had been cleared. How can I make it not do that?
We need to know how did you setup things up. Please post some relevant code. So we can investigate as well.
Hi Jeb, Did you figure this out? I'm stuck on the same thing. @Jeb$$anonymous$$erman42
Show your code from which you are assigning buttons events. we don't know how you setup your events as @NeverHopeless said, we need to see your code.
Fixed
I've made "canvas$$anonymous$$anager" to carry buttons (HUD/options) across to the next scene. These buttons perform sound clicks, scene changes, mute audio etc. These functions have their own managers. I simply needed to carry them across too, so obvious. -.-
Using -
public static Canvas$$anonymous$$anager instance = null;
void Awake()
{
if (instance == null)
instance = this;
else if (instance != this)
Destroy(gameObject);
DontDestroyOnLoad(gameObject); ...
Problem now is the buttons show on all scenes. What's the best way to stop this? FYI, I'm very new to this.
$$anonymous$$ake your class non-singleton and make events in the class and then access needed functions from the canvas$$anonymous$$anager instance. Then assign your events from the non-singleton class.
Answer by allenallenallen · Aug 13, 2015 at 05:08 AM
By coding it. Assign the buttons on load scene.