Sites

Menu

Set up tranform synchronization for an entity

Set up your worker connector

You need to add the underlying systems to your worker. Open your WorkerConnector implementations and add one of the following lines to the HandleWorkerConnectionEstablished method.

If this is a client-worker:

    TransformSynchronizationHelper.AddClientSystems(Worker.World);

If this is a server-worker:

    TransformSynchronizationHelper.AddServerSystems(Worker.World);

Note: You may need to override the HandleWorkerConnectionEstablished method in your WorkerConnector implementation if you haven’t already.

Add the components to your EntityTemplate

When you have a SpatialOS entity that you want the transform to be synchronized, you need to ensure that the required components are present on that entity.

We provide a helper method that does this for you: TransformSynchronizationHelper.AddTransformSynchronizationComponents. See the API reference for more information on this method.

var serverAttribute = "UnityGameLogic";
var clientAttribute = "UnityClient";

var entityTemplate = new EntityTemplate();
entityTemplate.AddComponent(new Position.Snapshot(), serverAttribute);
entityTemplate.AddComponent(new Metadata.Snapshot("Monster"), serverAttribute);
entityTemplate.SetReadAcl(serverAttribute, clientAttribute);
entityTemplate.SetComponentWriteAccess(EntityAcl.ComponentId, serverAttribute);

// Add the transform components to the template.
TransformSynchronizationHelper.AddTransformSynchronizationComponents(entityTemplate, serverAttribute);

Note: Typically you want to delegate authority of the transform components to a server-worker. This prevents a client from changing its own position in the game world. This, of course, is subject to your own design constraints.

Add the TransformSynchronization MonoBehaviour to that entity’s prefab

As the Transform Synchronization Feature Module supports GameObjects only, you need to ensure that you have a linked GameObject to your SpatialOS entity.

See our GameObject Creation Feature Module documentation to get this set up.

Open the prefab that you want to be linked to your SpatialOS entity and add the TransformSynchronization MonoBehaviour to that prefab. It should look like the following:

Add transform strategies to the TransformSynchronization MonoBehaviour

The behaviour of the Transform Synchronization Feature Module is dictated by which strategies are attached to the TransformSynchronization MonoBehaviour. Each strategy can be classified as either a “receive strategy” or a “send strategy”. See our complete documentation on the transform strategies to learn what each of them do.

You may need to create instances of these strategies as they are scriptable objects. Select Assets > Create > SpatialOS > Transforms to see the available strategies.

An arbritrary number of strategies can be specified, but only one per worker type, for either send or receive should be added. The Worker Type field on the scriptable object corresponds to which worker type it will apply to.

Our recommended receive strategy setup

Our recommended send strategy setup

Currently only the RateLimitedSendStrategy is available and thus is the recommended strategy.

Search results

Was this page helpful?

Thanks for letting us know!

Thanks for your feedback

Need more help? Ask on the forums