Saving Chosen Character

Fairly simple question I think…

If I have a character selection screen, where do I save the chosen actor so I can spawn it when the game loads?

Is there any class that persists across level loads?

Thanks all,

  • Austin

Depending on the engine version you are using you have two options:

Since 4.4, if I remember correctely, they added the “GameInstance” object.
The GameInstance will persist and keep all data for the whole time the game is running, i.e. even between levels and everything.

Second option is to use a SaveGame and save it to a SaveGame slot with that data when exiting the menu and reload it back when at level start.
That will even persist between games, i.e. completely exit and close the game and restart later.

To use GameInstance or SaveGame, create a new blueprint with the according class set as parent and add variables to it for everything you want to save - make sure your variables are set to be publically accessible (the little “eye” button on the right to the var name).

If you created a GameInstance blueprint you also need to set it in the project properties where you also set default game mode and startup map, the last option on that settings page is the reference to the GameInstance class you want to use.

For GameInstance you then call in you your (level)blueprint the “Get GameInstance” function, or “Create SaveGame Object” for a SaveGame.
You then need to cast the returned object to your blueprint, after that you’re ready to write your values into it.

In case of the GameInstance that’s it, load the new level and access the stored values the same way (create object → cast → read vars), for the SaveGame you first need to call “Save SaveGame to slot” function and in the level call the “Load SaveGame from slot” to get it back.

Unfortunately I can’t make screenshots of examples at the moment, but I can prepare some later tonight when I am back on my PC where I got UE4 installed.

Hope this already helps a bit :slight_smile:

Very useful, Thanks a lot!