How to carry variables through levels with game instance

Hey so I am trying to make a game where you need to collect items. The problem that is happening though is I don’t know how to carry the variables through levels. I tried doing this with a game instance by having those variables in the game instance and making an event tick to constantly set the game instance variables to the characters variables. Then when you open a new level the characters variables get set to the game instances. Any ideas why this is not working?

you have the game instance set to be the one used in the project settings right?

also i wouldnt set the variables on tick it would probably be much better to initialize the variables on begin play. if you have the variables being set on tick then you may have a hard time updating them and its not a efficient way to get this done.

You’re doing it backwards. You want “game instance” to SET “player” variables after you switch levels not the other way around. Before you leave a level you want “player” to SET “game instance” variables.

So you play level 1…collect 500 gold then you want to travel to level 2. What you do is cast to game instance FROM player and SET “Game Instance” gold = player gold.

Then you open level 2. Player gold = 0 because it isn’t carried over from level to level BUT “game instance” gold = 500. So now you want to SET “player” gold TO the “game instance” value and continue on.

This is usually best accomplished with functions. So just before “end level” call a function that sets game instance variables to current player values.

Then on level start, you can have the level BP call a function that sets “player variables” to game instance values. Problem solved!

Also just set them in the game instance whenever you set them elsewhere. Maybe even just only store them in game instance and nowhere else if youre not doing multiplayer so you dont have to copy the values around