UDN
Search public documentation:

ReplicationVariableReplicationNotes
日本語訳
中国翻译
한국어

Interested in the Unreal Engine?
Visit the Unreal Technology site.

Looking for jobs and company info?
Check out the Epic games site.

Questions about support via UDN?
Contact the UDN Staff

UE3 Home > Networking & Replication > Variable replication notes

Last tested on UDK Mar, 2011

Variable replication notes


Overview


There are some special rules that should be observed when you are dealing with variable replication within your game.

Vectors


Vectors are sent over the network is three signed integers rounded up to the nearest value. Replicated vectors can only stay within the bounds of (X=-1048576.f, Y=-1048576.f, Z=-1048576.f) and (X=1048575.f, Y=1048575.f, Z=1048575.f). Values that go above or below this range are clamped upon sending.

If further precision or larger bounds are required then you will need to create your own struct with three floats in it or to simply send each component separately.

Vector replication tests

Here is what the client receives when the server replicates changed values to the client. As you can see, vectors (Vector; Red) lose their fractional components. Vectors that are used within other structs (TwoVectors; Green) also observe the same behavior. Structs that look like vectors (Vector4; Yellow, Vector2D; Blue) don't get compressed in the same way as vectors, thus they are sent with full precision and standard 32 bit ranges.

VectorReplicationClientConsoleWindow.png

Here is what the server is sending to all clients.

VectorReplicationServerConsoleWindow.png

Rotators


Rotators are sent over the network as three unsigned bytes. Thus the smallest unit transferred is 256 unreal unit rotation or 1.406250 degrees or 0.024543 radians. Although some precision is lost, the difference is so small that it is not visually noticeable.

The calculation per component is done as replicated_component = (component >> 8) & 255. This will change any value, positive or negative, into a value between 0 and 255. On the receiving side, it is done as component = (replicated_component << 8).

If further precision is required then you will need to create your own struct with three integers in it or to simply send each component separately.

Rotator replication tests

Here is what the client receives when the server replicates changed values to the client. As you can see, rotator components under go the above transformation and then sent. When the client receives the replicated values, they get transformed on the client.

RotatorReplicationClientConsoleWindow.png

Here is what the server is sending to all clients. To double check, RotatorTest:

  • RotatorTest.Pitch
    • 59467 >> 8 == 232
    • 232 & 255 == 232
    • 232 << 8 == 59392
  • RotatorTest.Yaw
    • 9170 >> 8 == 35
    • 35 & 255 == 35
    • 35 << 8 == 8960
  • RotatorTest.Roll
    • -12242 >> 8 == -48
    • -48 & 255 == 208
    • 208 << 8 == 53248

RotatorReplicationServerConsoleWindow.png

Structs


Structs are sent over the network in a single pass. Other than vectors and rotators, they are not specially compressed in any other way. Structs are either sent all at once or not at all. Thus it is not possible to update a single component of the struct and then only send the changes. You can still do this manually however by sending individual variables and then compositing them together in the struct. Thus, in general be careful when replicating large structs.

Struct replication tests

Here is what the client receives when the server replicates changed values to the client. As you can see, all the variables are getting updated in a single go.

StructReplicationClientConsoleWindow.png

Here is what the server is sending to all clients.

StructReplicationServerConsoleWindow.png

Static arrays


Static arrays are sent over the network efficiently by only sending the changed values. This rule however is overridden if the static array is within a struct, due to the "all or nothing" rule attached to structs. Thus avoid large static arrays within structs, as then the entire struct is sent even if a single array value is changed.

Replicated static arrays must be less than 448 bytes. Thus some static arrays of structs cannot be sent due to this restriction.

Replicated notification of static arrays only work on the first initial replication update. Subsequent static array replication updates do not call ReplicatedEvent. However, if other replication notified variables call ReplicatedEvent, the static arrays then also call ReplicatedEvent. Static arrays within structs will always called ReplicatedEvent. Thus, if you are finding that static arrays aren't calling ReplicatedEvent at the appropriate times, replicate a boolean at the same time to make sure that ReplicatedEvent is called.

Array replication tests

Here is what the client is receiving from the server.

ArrayReplicationClientConsoleWindow.png

Here is what the server is sending to all clients.

ArrayReplicationServerConsoleWindow.png

Dynamic arrays


Dynamic arrays are not replicated at all. If you need to send a dynamic array of actors, you can use linked lists to do this. Otherwise, you may need to create your own replication method. One method is to do it via remote procedure calling, but you can easily overload the bandwidth available to you. Thus, dynamic arrays should be reserved for non replicating situations.

Downloads


  • Download the source code. (ReplicationVariableExample.zip)