Hi,
I’m having trouble in getting the hang of store/save variables upon OpenLevel/EditorClose.
I’ve learned that the best way to store information between levels is to store the variables on GameInstance - but I’ve also learned that things like Player Name and Current Score are better to store inside PlayerState for online gameplay.
As the default PlayerState exposes PlayerName only as Readable, I created a BP derived from the default PlayerState and created a PlayerName (String and Replicated) variable on it which gets the default PlayerName on BeginPlay:
As it is, it will obviously reset the variable on OpenLevel to the default PlayerName, but even if I don’t declare nothing on BeginPlay, it will always reset when entering a new level.
I know this because I have a ChangePlayerName inside my menu, which resets everytime I enter a new level:
So, what is the best approach to store variables on Editor Close/Open Level when they’re stored inside a PlayerState?
I’ve heard about the CopyProperties inside PlayerState but I couldn’t get it to work, although it prints as it should (with different before and after values):
I also been reading about Create Save Game Object and Load Game From Slot but still didn’t give it a try.
I think it all comes to the same question, in GameInstance my stored variables don’t reset to default when opening a level, while the ones stored in PlayerState do.
When I close the editor, both GameInstance and PlayerState variables reset to their default values, which is something I’m trying to solve too - but for now, I would be appreciated if I could get my PlayerName variable to not reset on opening level.
Thanks for reading.