Hello, I am trying to build a system for my multiplayer game in UE 4.27.2 that will read a variable from the server on the client and do something based on that variable’s value. The variable is set before the player is spawned and the variable is stored in the Game Instance. When I play the game and I look at the debugging for the player I want to get the variable… It is set properly in the (Server, spawned). No problems. But when I get that same variable in the client (Client, spawned) version… it appears as if it hasn’t been set. I looked around online and determined I may need a Game State and Player State system for this, but those reset between levels and game modes which won’t work with the system I’m trying to build.
I feel like I’m doing something very basic wrong here. I essentially need a Game State (because it can be accessed by both server and client) that is persistent. Can anybody help me out? Thanks for any/all support! <3
Yes, GameInstance only exists where the game is launched. Each client and the server have individual game instances that are not connected in any way.
You need to use something that exists both on the server and the clients. Game State or Players State will do, or even Player Controller.
Yes, they are reset. You can save the variable in the Server’s GameInstance, but you’ll have to manually set it on BeginPlay(), in Game State or Players State or whereever you’ll end up using it.
2 Likes
This ended up working once I tinkered around with it more and embedding replication into the Game State value getter custom events.