How to replicate 1000 struct data?

Imaging this game scene, there are 1000 plants or trees in game, they will grow every tick, so there must be a float value to record its age, and use location(FVector) as a key to find it.
so there is TMap<FVector, float> mapLocToAge;
the problem is ,how to replicate this data to all clients?

You only need to replicate those objects when they are spawned.

First, you should make “age” be a calculated value, and instead store the “spawned at time” value as the base property. This means nothing changes on the entity after it’s spawned.

Second, you should figure out how the objects get spawned. If they are part of the level, then no replication is needed; the only value needed at runtime is “how old is the level.”
If you spawn the objects manually, then if you spawn them one by one (not all in a single swoop) then you can probably replicate them using regular event broadcast. Might want to build a hierarchical instanced static mesh based actor to render all the plants, but the “spawn a new plant” message can be a reliable RPC on that actor.

Third, if you spawn the objects as a single “spawn them all” operation that is initiated by the user, then you need to replicate not each object, but the “seed event” for the objects. So, for example, “threw the spawner bomb at point X, and placed each seed using a random stream seeded with value Y.” You’ll have to work at it to make sure that the random generation is indeed deterministic; for example, moving replicated actors can’t block any collision checks made.

In all of these cases, only a very small amount of information needs to be sent in any one frame (if any at all.)

3 Likes