Download

Variables that persist through level changes?

Hi

What I’m trying to create is a variable (health) that you can select on the map screen and then for every level you go into, the player starts with that amount of health. Since I’m working with blueprints though, the blueprints are destroyed when you switch level and new instances are created so I don’t really know where to go.

I’d also like to store some other information, like the player position on the map screen, record times for levels and such and the best of all would be to be able to write them to a file so they’re stored until the next time you play the game.

The super ugly hack version is having three copies of the same map and the game just loads the proper one depending on what amount you selected, but that seems quite stupid.

Any ideas on where to start?

https://www.youtube.com/watch?v=6l7uynUwm5M

Have you tried to set and retrieve variables in the Gamemode blueprint. I think that survives a level load but I’ve never tried it myself. Good luck.

I might not be correct on this topic, but when I check source code for respawn, it seems that GameState and PlayerState could survive through level change.
So I would assume that variables on them will survive as well, I haven’t try that yet, so it’s just my guess.

They mentioned in the last podcast that they would have globals in the next release that would persist over level loads

I think the playercontroller Blueprint persists between levels, so you could try storing information about health and other player stats in there. I haven’t tried this myself, though, so I’m not 100% sure.