How to use game instance to transfer a spawned player between levels

I followed this tutorial by Unreal Engine: Blueprint Implementing Local Multiplayer | Live Training | Unreal Engine - YouTube

So I have a 4 player couch co op game where you can drop in and drop out, on loading the next level, everyone has to respawn (drop in) again. How do i carry over if they are already playing or not. I know its has to do with storing a game instance, but not sure how to get the variable of players spawned.

Many thanks in advance.

Gameinstance is a class that survives for the entire instance of the game.

Now, lets say you have a variable “IsAlive” stored in Game instance.
Create a PlayerInfo Map (Dictionary) of PlayerBP and PlayerData struct.

The playerdata blueprint would contain data like IsAlive, Score, Coins etc.

When you go to new level, iterate the through the PlayerInfo Map and spawn the player based on the data (as the data would contain if the player is alive or not)

I’m finding it hard to understand. Could you perhaps elaborate

So game instance is eternal for the application. As for as the exe stays alive , the game instance will be running. The gameinstance is not destroyed when maps are changed. So any kind of persistent data is stored in Game instance.

For example,
Step 1 : Create a Structure called player data. Put all the player related variables there. For example you want to track if a player was alive or not when the scene changes. So create a bool in that struct called IsAlive. Also create an integer value in the struct called score (just for understanding).

Step 2: In the gameinstance class. Create a Map called PlayerInfo ( dictionary) that has the Player Actor BP as the Key and the PlayerData structure as the value

Step3: When a player dies, GetGameInstance → cast it into yoru gameinstance. Now grab the dictionary and update the struct of the Player. Lets say Player 2 died. Grab the Playerinfo and modify the Value for the Player 2 key.

Step4: When a new map is loaded. Grab gameinstance → cast it into your gameinstance → get the map. Now iterate through all the player (Keys) and get their Value which is the player data. Now if the data has the ISALIVE set to true, it means the playr didn’t die in the previous scene, so you can spawn him. If the IsAlive is false, don’t spawn him.

Thank you for your help, after reading through what you said a few times and a few experiments, I’m getting closer and closer to what I want. Much appreciated.

Glad to help, if you are still confused, think of it like gameinstance is like a singloeton for the entire application. It is always alive. So the state of all the variables that get destroyed during scene change can be saved in gameinstance and loaded again when the new level is loaded.