Hello, i made a character selection menu. I set character class variable in game instance by widgets. And when you host a game, PostLogin event in GameMode works, then it spawns the class where is in game instance. It works for server. I mean, if you select red character and host a game, you become red. But when another player which selected blue character comes to level, it becomes red too. Client is always same with Server. It is weird. Am i missing something?
I set the character class variable where is in game instance via widgets.
I too am experiencing such problems. I’m storing vars in my game instance and I assumed that when reference the Game Instance from my client side that it will pull the variables stored on the client side itself, but it seems to be always referencing the server-side Game Instance instead of the client-side.
Yes. You and @ZPaul2Fresh8 are missing the fact that OnPostLogin is a GameMode (server-only actor) function that fires only on the server, and thus you are referencing the GameInstance server-side. The value you are looking for is found client-side. How will you access it then? You can fire a client RPC on the New Player instance and then pull the info you want from the GameInstance client-side, validate it, and send it back to the server via a server RPC.
If you are seamless travelling I would go for a different apporoach that entails using PlayerState to store such data and retrieve it using its function CopyProperties.
Thank you for the reply and the handy compendium! I guess the confusion came from the OnPostLogin event having the connected user’s Player Controller.
I thought referencing said user’s Game Instance within their Player Controller’s constructor would give me that user’s Game Instance variable and access to the vars defined within it, but I’m guessing this is incorrect?
The thing is that you don’t access GameInstance inside a PlayerController’s constructor. Even if the GameInstane was valid, you will have a hard time to tell if you’re on the server or client there. That’s why you need at least a function that gets called at a later point in time like BeginPlay to do your thing and to do a HasAuthority check (or check the NetMode) to see whether you on the server or client.