How do I set a boolean variable in the GameMode BP from a main menu widget BP?

I am attempting to implement a load game feature in my main menu and want to direct my load game script to fire only when the “Load Game” variable is set to true. I believe I am setting the bool properly in the widget blueprint however after I load the level and have the GameMode BP print the boolean value it stays “false” I feel like I am missing something obvioius but after searching for hours I can’t figure it out and hope someone can show me the magic light bulb!

Main menu screen with Load game button

121004-main+menu.png

BP script behind load game button

My way of ensuring my load game event doesn’t fire before the level is loaded…

121006-level+load+event+fire.png

Event to print value of “Load Game” Boolean variable

121007-gamemode+print+boolean+value.png

After clicking “Load Game” from my main menu the level loads but the boolean still says false which is its default value.

121008-boolean+value.png

Thanks Looniper but I am having trouble following how I can apply that to my scenario…I am storing my bool in the gamemode and casting to it to set it. (wanting to know why it isn’t actually setting) Are you saying I should be creating a reference in the widget to store the boolean variable?

Ahh I will wait on the rest of your answer then.

I was thinking that the GameMode loaded first then the level then actors in that level…from what you are saying though the mode loads after the level so it can’t set the boolean in the mode because it does not exist yet correct?

There are various ways to pass data between blueprints, but if there is any chance of Multiple players you want the connection between them to start With the Player Character.

Eg… When creating the widget or displaying it –

  • In this example, I have an Event in the widget graph to Assign Owning Player - taking a Reference (to self in the player) to a Character.

Then you can just drag off the reference that is set to modify variables stored in that character.

121012-reference_owner_widget.jpg

The Character can reference its own Game Mode and send that reference to the Widget as well.

This way you can be sure the data is being passed between a Player Character and their associated Widgets, etc.

But that, in itself, does not solve the problem you are having. You are using a Game Mode to store data between level changes.


Modes are completely reloaded after a level change.

So you are having the Level Blueprint check a bool’s value that has been replaced by the default value.

Use a Game Instance to store data that needs to persist between levels as long as the game is running.
Modes are not reliable for that purpose.

I was looking for an example to show…

Simplest terms —

GameModes are loaded After a Level - and each time a level is opened.

So data saved in one is “lost” (reverted to the what is saved in the Mode’s Blueprint rather than what you have Set it to be) when you change maps.

Game Instances persist throughout. So if you use one for this, you will get the result you want.

121020-data_by_mode_2.jpg

The value set directly in the Mode asset is reloaded with the Level.

But…

121032-data_by_inst_2.jpg

The value stored in the Game Instance is carried through with the level change.

(Be sure you edit Project Settings to set that given Game Instance as the one your game is using)

More accurately, the GameMode is "Re"loaded each time the level changes.

That is why you are getting the False - as far as the game knows you never set the value (once the new level loaded). It is reading the value set in the Blueprint itself, not what was loaded into memory (because that was replaced)

Ahhaa! Yep that makes perfect sense and it finally clicked for me. Thank you so very much for taking the time to explain it to me and lay the process out step by step! It is greatly appreciated.