Problem with multiple buttons when changing scenes

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By DrSpyros

This is an issue for a long time,

So in a game I have, I have 2 scenes. In one of the scenes I have multiple buttons that are attached to the same script, and when a button gets pressed I disable it. But if I change a scene and go back the button has been enabled again,

Is there any way to change between scenes and the button staying as it is?

The script also has a timer for when the button should be again enabled, idk if that’s gonna be a problem.

:bust_in_silhouette: Reply From: jgodfrey

You’ll want to store the state (enabled / disabled) of each button and restore that state after the scene changes. Since the state storage itself will need to survive the scene change, I’d recommend that you store the state in an Autoload script. Then, on scene change, retrieve the button states and restore them.

Wouldn’t that mean I have to make let’s say 5 different variables for each button? I want one button to be disabled seperatly

DrSpyros | 2023-01-09 14:52

I don’t think so. I’d probably just create a Dictionary that is keyed by the buttons themselves with values representing their state. Then…

  • When a button’s state changes, you’d record it in the Dictionary
  • Upon scene change, you’d spin through that Dictionary and restore the states as recorded.

jgodfrey | 2023-01-09 15:13

Huh, that actually helped a ton! I also did not know how to use dictionaries, but I researched that. So I learned to things today :3

Thank you so much!

DrSpyros | 2023-01-09 18:28

Happy to help. Post back if you get stuck.

jgodfrey | 2023-01-09 18:36