Make widget button set variable inside level blueprint?

My widget has buttons and all of them would set a variable to a new integer value. I have tried using a reference of the widget and a get node branched off of the reference, but the value never commits to what it is set at. The widget is in a separate level, so the value is set, then the user is transported into the main level w/ level blueprint that inhibits the set value from the referenced widget to the get int value of the variable. Anyone know what I am doing wrong?

The variable must be set in another level bp, in a separate level there is just a widget and its buttons which when pushed have to set a variable to some integer. This variable never works though inside the main level blueprint.

I can’t have the widget in any other level, that’s why I’m trying to get the variable into another level’s blueprint, b/c there is nothing except a widget in that level.

GetGameInstance → CastToGameInstance gives me an error ‘Return Value’ is already a ‘Game Instance’ you don’t need CastToGameInstance.

don’t store long term variables in the level blueprint. if you want to transfer variables to another level, store the variable in a gameinstance or savegame.

try not to use the level blueprint unless you want to do something unique, which is only done in that level, and does not affect anything in any other level. even then, its usually a better idea to use actors placed in the level rather than putting stuff in the level blueprint.

you don’t need to put the variable inside a level blueprint. the widget can store the variable inside a custom gameinstance, and in the other level, you can read the variable from your gameinstance.

in the widget, use GetGameInstance, cast to your CustomGameInstance, and set the variable. in the other level, you can GetGameInstance and get the variable.

first, you should make a new blueprint based on GameInstance, called something like MyGameInstance. you can add any variables you want to keep between levels to that blueprint’s list of variables. then, under Edit > ProjectSettings > Maps and Modes > at the very bottom, you can set the Game Instance Class to your custom MyGameInstance.

then when you use GetGameInstance inside a blueprint, you can cast to MyGameInstance, and set or get its variables.

I second this. While there are always dozens of ways of doing a thing especially when dealing with code you want to strive for the most correct way to do it. Otherwise things get messy and complicated and introduce instability.

While it may be frustrating to rework your architecture to accommodate what is suggesting is the best option from my understand of the issue.

I click the button to assign variable W to an integer but in the level blueprint the get W returns no value

I tried this with a blueprint actor just as a billboard to store the W value and the same thing occurred.

that should work. did you set Edit > ProjectSettings > Maps and Modes >GameInstanceClass to MyGameInstance?

I had set it to GameInstance instead of MyGameInstance. This allowed my variable to be set! Thank you very much, I thought it might have been a bug.