Read a level blueprint variable in a widget


I created a widget with which I would like to retrieve the value of a variable located in the “level blueprint” and set as public but I don’t know how.

Can anyone help me?

Level BP is not meant to be referenced/read by another BP.

What is the values purpose?
Does the level BP modify it?

In the widget there are 3 buttons to define the level of difficulty.

When I click one of the buttons lights up and the other two go out. I manage these interactions directly in the widget.

I need the button I clicked to remain stored even when I close the widget and re-create it.

Instead, the widget resets every time I destroy and re-create it. So I thought of storing the value of the variable somewhere else.

Don’t destroy it then. Create it once, store the reference and then show / hide it instead. Or store the game difficulty settings elsewhere, how about in the game mode.

Thanks a lot for the answer. If I wanted to store the variable elsewhere than the level blueprint, how should I proceed? Where can I register the value? Do I create a special blueprint?

You can keep it the widget if you must. Just don’t destroy the widget as it will obviously reset it.

As mentioned above, Game Modeis reasonable place to store settings - it’s a framework class accessible from anywhere. Any time a blueprint needs to access some sort of universal data, you can Get Game Mode -> Cast and get your data. You can also store it in Player Controller, Pawn. Does not really matter if it’s for a single player game.

If you need the setting to persist after loading another level, use game instance. If you need the setting to persist between game sessions, look into save game objects.

So what’s the game loop here. You get to choose difficulty for every map you load or?

Just to clarify that:

The above will create the widget if there’s none. Any consecutive interaction will simply reuse the existing widget, preserving any data you might have stored inside.