GameInstance and how to save players in there (solved)

Hi,

I am working on local mupltiplayer game and so far made a lobby where the players enter and input their Player Names. After enough players joined host can start the game. They servertravel to another map where the game begins.

Problem: I dont know how to save player data, I need to save their PlayerNames so after the servertravel they still have their Names. I guess it works with GameInstance.

I worked with GameInstance before, but not in multiplayer. So can someone explain to me how it works in Multiplayer and how can I save players in there and then get them out. Maybe each player has its own GameInstance, or there is one global that is on server? And do I save in there PlayerState or only Names?

That is already the case. The gameinstance is created when the player starts the application and is destroyed when the player closes the application; it is persistent through the application’s lifetime.
For player names, there is already a variable & function for that in the player state.

When you server travel, the players are disconnected from the server, the server changes levels, then the players reconnect. This will reset all the stuff stored in you gamemode classes (game state, player state, etc.). So all you do is store those things in the gameinstance, then whenever the level changes, you reload those from the gameinstance; in other words, the players “re-login” after each level change.

So, in your player state, you would put an event that would grab the username (and any other stuff) from the game instance whenever the player joins. Though, you should probably be storing gameplay-specific things (like scores) on the server only so clients can’t cheat.

1 Like

Thank you, already solved

1 Like

How did you solve it?

The guy above explained it.