Set/Get variable

Hi,

I have setup a menu system before the game loads my main level in which you can choose a difficulty by pressing a widget button.
In my character bp I have a float for the difficulty which will contain 1-3, I’m trying to set the variable on click, which should be pretty simple, then when my level loads read this variable but I’m having trouble with this. It seems I can read it, but can’t set it. Any help?

Thanks

This is in my widget blueprint where I wanted it to set the variable
set.png

This is in my level blueprint, I want to get this variable as the level begins but it just seems to return the default value as if it was never set
get.png

First of all, you’re trying to get the player pawn in the main menu, is it really spawned there? Check if the cast fails.

Secondly, are you saving and loading? When you switch levels, every actor in the previous level is destroyed and then the new level loads with whatever you put in it. Your character does not inherently remember anything from previous levels, so you need to implement saving and loading, or using the … game state? which persists between levels.

Hi, SilverfireInt.
You must make you logic correct - variable difficulty can set in game instance for example.

All classes are recreated when a level is opened. This means you cannot store any information over different levels. The only class that isn’t recreated is the GameInstance. You need to store such information in that class. Alternatively you could use a SaveGame object but the GameInstance is most likely what you should use here.

Thanks for the fast replies.

I found this youtube tutorial which explains if anyone else is having a similar issue.
All sorted thanks again!