Download

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
1c713c965891b26c5aa33627ff8e525bce7edc38.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
fec7d2874e5b899116b1e655edf3042fbc848a1a.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.https://youtube.com/watch?v=K_4CWDxwufg
All sorted thanks again!