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?
asked Jun 10 '18 at 04:13 PM in Blueprint Scripting
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!
answered Jun 10 '18 at 05:28 PM
Nebula Games Inc
Follow this question
Once you sign in you will be able to subscribe for any updates here