GameState variable replication issue?

Hey everyone! I’m new to networking as a whole and have come upon an issue I can’t seem to solve, so any help would be appreciated.

Each PlayerState contains a current_team variable, an array of CharacterStructs (a party system, really). When the game begins, the GameMode tells the GameState to gather all of the CharacterStructs from both players’ current_team array. This collection is done server-side, collecting the current_team arrays and loading them into one of its own variables, either “_team1” or “_team2”. Then using a multicast event I spawn those characters out into the world on their respective start positions.

Get All Characters:


Here is where something gets messed up though. The SpawnCharacters function spawns a custom PlayerPawn_BP instance, basically a blank slate. I load this blank slate with all of the information held in the _team1 or _team2 variable (each are an array of 3 indices, each index a CharacterStruct. The CharacterStructs hold the skeletal mesh to spawn, the pawn’s name, heath, etc.) If I play with a listen server, the character’s spawn correctly, but only for the listen server’s PlayerState. For all clients, all pawns spawn, but they are still blank slates, having none of the _team1/_team2 data loaded into them. This makes me think that when the _team1/_team2 variables are written and the clients draw from those variables to spawn their pawns, they can’t access the correct data. However, both _team1 and _team2 are already set to replicate.

Any help would be greatly appreciated, thanks!

Don’t think variable replication is the real issue here. You shouldn’t really be spawning the players in the GameState, do that in the GameMode.

Also, it seems you’re trying to have each client spawn each player? The server already does that, so just have the server spawn everything, and have the clients grab the names/HP/whatever of each player from the GameState

Hey, thanks for the response. I was under the impression that the GameMode was used primarily as a game manager, a top-level functionary, whereas the GameState was designed to do everything associated with the game itself, like spawning, keeping score, etc. However, I rearranged my flow like you suggested and it ends up working much better when it is in GameMode. This solved one of my problems – I was grabbing all characters and spawning them OnBeginPlay. However, since the GameMode/GameState are initialized BEFORE PlayerState, nothing existed for it to grab except for what was on the Server. Now I have functionality to grab all in-game players and wait for both to join.

However, the _team1/_team2 data still seems to be getting lost between the server and clients. All pawns spawn correctly on the server, but only the blank slates spawn on the client:


Any ideas? Since they are now in the GameMode and nothing is replicated regardless, it doesn’t seem like having those _team1/_team2 variables flagged as Replicated was the real problem.


Is the actual spawning still Multicast? Networking is a bit complicated. I’d have to see the actual code to know for sure what’s wrong. Clearly the clients aren’t getting the variables needed…

Yeah, it is.

The spawn function is exactly the same as it is above (the only difference is that now I grab the player controller and assign it as an owner of each pawn as it is created). The pawns are being created and assigned the correct owners, it seems like its just the _team1/_team2 variables aren’t carrying over to the clients.

The thing I would do is start adding debug prints after ever single instance of the variables being used to find out when/how the variables are getting lose. For example, you should do “Get All Characters” just on it’s own, and then have a special event that will simply print the result of “Team 1”. I have a feeling the actual “Get All Characters” is the problem. Is it actually being ran on the server?

Vague answer, sorry. But to be honest your setup is confusing to me, I’d handle it much differently

I figured this out yesterday, it all came down to a lack of understanding on my part. I fixed it by letting the GameMode handle finding all the players in the game and gathering their respective teams, and feeding that to the GameState to spawn in the correct locations. This replicated it to all of the clients, and then RepNotify functionality makes sure all of the client-side pawns have the same properties. Thanks for you help though, it was much appreciated!