This is probably the easiest method, as all you have to do is simply save the data before travelling to a new level, and retrieve the saved data after you’re done travelling to that level.
I think it’s been written for experienced developers because I, as a beginner, and I don’t know where I have to retrieve the PlayerState.
Now, I retrieving it in the GameMode, PostLogin event:
I say solidly that yes, the game instance persists when travelling from server to server. However the only way you will retrieve from my knowledge the player state from the game mode is by first casting to the player controller from the OnPostLogin Function and pulling off the “AsPlayerController” and retrieving the player state and then casting TO that specific player state.
From that player state you can retrieve functions locally from the individual game instance from inside the player state.
Casting to the game instance from the OnPostLogin function will result in an accessed none scenario as it’s existing on the client only. It just doesn’t work.
In my experience, I’ve needed to run server events inside the player state that call functions also inside the player state from “Run On Owning Client” events. So ServerEvent->RunOnOwningClientEvent-> local logic.
The player state will reset to default any time a level changes or server travel occurs. As far as I know everything by default resets to include the player controller as well. Only the game instance will persist exactly as the variables are set until you either change them or the game is turned off. There are a number of complicated ways to move data across level changes, but the game instance is the easiest method in my opinion.
If you wish to maintain the game instance in a persistent state, that will require save game.
p.s. I would say ideally the most solid way to communicate via game mode to players is to do so from game mode to the game state and down to the player state.
Would you be able to provide an example with pictures? I’m having a super hard time spawning with my chosen character when joining a dedicated server, but it works perfectly in P2P.
I populate a client side Game Instance with my chosen class and then spawn as this class in my game mode on new player joining. It works great in P2P and stand alone but for some reason the gameinstance is either resetting when joining the dedicated server or for some reason the cast to the client side game instance is failing.
Well, the game instance isn’t going to replicate when entering the server. You might notice that on P2P because the host client is also acting as the server and you see that game instance.
You’ll need to run some Rep Notify functions that retrieve those variables and replicate them over the server to the rest of the clients or run some RPCs after your spawning logic. You can get those variables from the player controller by casting to the game instance to get them and set them replicated and also cast to your character to set skeletal meshes and such.