How to get variables from an older level?

Hey All.
I am attempting to move a bunch of variables from one widget present in a first level to a new one bound to a different player controller in the next level and I don’t know where to begin, I think that the problem stems from the fact that I don’t know what persists across levels but I can’t seem to find any information on that either. As always, any help is greatly appreciated.

Hey there @TruffleExplorer! So if your game is single player, you may want to house any variables that are going to be persistent in your game in your GameInstance. This class basically retains data throughout your play session.

To do this, create a new BP with a parent of GameInstance. Then put your variables you want in there.

Then go to project settings and set it as your game instance.

If they are global variables that make sense to be in there, you can house them there entirely. Then you’d convert your widget to either read the values directly from the gameinstance (my recommendation) OR have them take the info from the GI on BeginPlay and have a method to update it as you change levels. Just a quick cast to the instance itself and you can get, set, or trigger functions persistently across your game!

1 Like

Thanks man!

1 Like