Hello everyone,
I’m looking for help solving a frustrating issue I’ve been stuck on for a while. Despite trying several approaches, I can’t get it to work as expected.
TL;DR
Struct data in GameState is not replicating properly to clients — particularly keys that are themselves nested structs, even though the parent struct is marked as Replicated.
Context
I’m building a 2D backgammon game in Unreal Engine. I store the entire game state in a single custom struct, which includes:
Player sides
Dice results
Board pile positions
Whose turn it is
Other in-game metadata
This struct is stored in the GameState, and it’s marked as Replicated.
The logic to initialize the board (generate dice, set turn, and populate the board) happens inside the GameState and is run with Server authority.
The Problem
The listen server sees all the data correctly.
The client only sees partial data:
Dice values and current turn replicate correctly ().
But the board state (a nested struct or array of structs) is empty ().
Even though everything is in one struct and that struct is marked as replicated, some fields never get updated on the client.
As a test, I converted the entire game state struct to a JSON string on the server and fetched it on the client — and it showed the correct, up-to-date data!
But when I access the actual struct variable on the client, it shows only default values. This suggests Unreal isn’t recognizing the change to the struct for replication purposes — even though the data is technically valid and exists on the server.
Game State can only be updated on the server. Widgets cannot make RPC calls. When a client needs to make a change to data it has to RPC the SERVER to make the change.
On Listen server the host client is also the server.
Looks like you are using TMaps, which afaik still do not support replication.
You can work your way around either by :
Replacing your Maps with Arrays of structs, including the key in the struct. Then when you need to find items by key you have to iterate the array. It is allegedly less optimal, but in practice iterating an array isn’t really slower than hashing the key, until you reach a certain amount of elements (around 50 according to other posts).
Move your structs to C++, where you can write custom serialization code to include TMap contents (search for NetSerialize / NetDeltaSerialize). Delta serialization might be difficult to achieve though. If you end up sending the whole map every time, it could impact network performance.
I can confirm that you are not able to replicate Maps and Sets in blueprints. I run into this exact problem few weeks back. I ended up re-thinking my approach and making a couple of arrays and I must say it actually made my blueprint code so much cleaner.
Thanks everyone for feedback, its correct, maps variables can not be replicated and i didnt know about that. I will try to structure data in different way