Why Do Global Varibles Gets Resetted?

I’m currently trying to fix a feature in my game that has to turn off the music when the player unchecks the button and then save it so when the scene is restarted the music won’t start playing.

But somehow the global varible that defines if the music will start at the beginning of the scene or not gets resetted every time the current scene is restarted or a new scene is opened. Even though i save and load it:
Ekran görüntüsü 2023-10-31 184900

These are the music on/off events:

These are the events to load the saved global variable:

Can you tell me what i’m doing wrong? I tried many things and none of them worked.

Hi you’re not doing anything wrong. And you’re not going crazy.

What’s happening is that, even if your boolean is true from loading saved events or from a previous scene, as soon as your new or reset scene is done loading, your scene sees that the checkbox is (by default) “checked” and so it must set the Musicoff bool to false because events tell it to. An extra step is needed in your beginning of scene events, so that if the Musicoff is True in the beginning, your scene will “uncheck” this box so that it won’t override Musicoff as soon as the scene plays.

This example shows how a way to do it similar what you are doing now:

But this is what I’d actually do since you don’t really need to save a value, you just need to know the state of the checkbox.

Edit Just for clarity. I randomly set the volume to 0 in the beginning of scene events. This doesn’t matter. You can set it to 5, 40, 100, it doesn’t matter because the actual volume is controlled in your event.

Wow i never thought about this. It worked, thank you.

1 Like