I think people get confused when they read “store data on game instance when chancing level for multiplayer”, while they are also learning about what is shared/replicated and what is not.
To make it simpler, Game Instace is the executable that is running on your own computer.
So if you open “MyOwnGame.exe” that will create a game instance, if you go and open it again myowngame.exe that will go and create another game instance, that is completelly isolated from the first. Same thing happens between “server and client”. The server .exe has its own game instance, while the client .exe has its own instance.
For new unreal joiners, when reading about stuff that exists in both server and client, I think for most, the game isntance seems to behave like server and client, similar to the player character or player controller, that exists in both server and client and are somewhat linked.
But that is not the case for game instance, yes it exists in both server and client, but there is no link between them, server has its own game instance while each client has its own game instance.
The best way to visualize it, create a brand new third person control game, create a new game instance, and set the project to use this game instance, and set multiplayer net mode to “play as client”, and number of players to 1, on init method of your game instance, set a guid to a variable string, like:
now on your third person character, on begin play, you can print your guid from the game instance.
Since this will fire on server and on client, it will output different values since each client has its own game instance.
this will play like:
in fact you don’t even need the branch, since each side will run its own version, it is exactly the same code, but two different values
Why one would use game instance? Mostly for configuration, things that will change from one computer to another. Like your own controller mapping, server has no idea what your control mapping looks like.
Or you are switching a map regardless if it is single player or multiplayer, and you have data on the game mode you don’t want to lose, you can store it in the game session.
Like, from the server perspective, switching maps, the info on game mode is lost, on the server game instance, the server can read the info from game mode, store in its game instance, load a new game mode, and set the values back on this new game mode. During all this, each client game instance will remain unchanged, they have nothing to do with the server game instance.
The only exception to this would be shared split screen multiplayer. Is not an exception, but I bet some will get confused, so when launching in a split screen, there is only 1 game running, so it will only have 1 game instance, regardless of the fact that there are two players characters.
So repeating the experiment above with a shared splitscreen, will in fact output the same uuid for all players, since they are all sharing the same game instance.
A fun experiment to do, if you really want to sink this down.
Configure your game to add 3 local players, while having the net mode to play as client, and number of players to 2.
This will run 2 clients + server, so it will have 3 game session, while also having 8 players