Skip to content

Replicate Annotation

ContronThePanda edited this page Dec 15, 2019 · 2 revisions

The @Replicate annotation controls how components or individual fields of components are replicated over the network in a multiplayer setting. (More information about components can be found here). It indicates that changes made on one side need to be replicated on all sides, and in what way this should happen.

Value

The value field indicates where changes should be replicated to and from. This should be a constant from the FieldReplicateType class. The four available constants and what they do are shown below:

FieldReplicateType Description
SERVER_TO_CLIENT The field will be replicated by the server to all clients connected to the server. This is the default FieldReplicateType.
SERVER_TO_OWNER The field will be replicated by the server to the client only if the client is the owner (i.e. the client belongs to the entity containing the component).
OWNER_TO_SERVER Functionally the same as OWNER_TO_SERVER_TO_CLIENT
OWNER_TO_SERVER_TO_CLIENT The field will be replicated from the owner to the server. It will be then be replicated by the server to all connected clients that are not the owner.

Initial Only

There is also an optional boolean initialOnly field. The value of this field determines whether to only replicate the field initially or not and defaults to false. This should be used for values which will not change during the course of the game and therefore do not need to be checked and copied more than once.

NoReplicate

There is also a @NoReplicate annotation which specifies the opposite of @Replicate: this field/component should not be replicated over the network.