I’m saving some properties of my pawn and when I press a button it destroys and spawns back with the data loaded but when I transition the level, the data does not load, the pawn is loaded with its default parameters. Can someone tell me why this is happening when I transition level but not in the same level if spawned again?
When spawning again you’re creating a new instance of the pawn, hence the default values.
If it’s player specific variables that needs to persist between re-spawns, I would recommend storing them in the Player Controller instead. That way they won’t be reset even if the player pawn is destroyed and re-spawned.
If you’re looking to have persistent variables between levels, use the Game Instance to store them.
Well, Like I said I’m making changes to my pawn and saving them using a button in UI. When I press a button, the pawn respawns and the values changed are still there but when I click on the play button and go to a new level, there are no such values there, only the default one. I’m saving values using the Unreal SaveGame class.
Which Play button do you mean? the play button in the editor or some button in the game?
If you’re using SaveGame, when opening the new level you’ll have to Load the save file and set the values in the new Pawn. How is the saving code set up currently?
Could you share code and screenshots of the save logic and buttons?
hi, how you are loading the save game, like in which class you are writing code