Set up basic spawning

Create an Entity Representation Mapping asset

You will need to create a new Entity Representation Mapping asset in your project. This asset describes a mapping between an entity type and a resolver. The resolver describes how a worker chooses a GameObject for an entity.

How do I set the 'entity type' for my SpatialOS entities?

You can set the entity_type field in the Metadata component when declaring your EntityTemplate.

The following entity resolver types are provided:

Resolver type


A basic 1-to-1 mapping of an entity type to a prefab.


An authority based resolver which picks one of two prefabs based on the OwningWorker component provided by the Player Lifecycle module.

To create an Entity Representation Mapping asset, right-click anywhere in your Project window and select Create > SpatialOS > Entity Representation Mapping.

Note: We recommend that you name the asset based on the worker type you will be using it for.

Select the newly created asset to view it in the Inspector window, then for each entity type in your project:

  1. Select the New Entity Type button at the bottom of the Inspector.
  2. Choose the resolver type that you want to use from the dropdown.
  3. Configure the resolver with the 'Entity Type' and the prefab(s) that it requires.
An example of what your Entity Representation Mapping could look like.

An example of what your Entity Representation Mapping could look like.

Set up your worker connector

You will need to add a reference to your worker's prefab mapping in the worker.

[SerializeField] private EntityRepresentationMapping entityRepresentationMapping = default;

You then need to add the underlying systems to your worker. Open your WorkerConnector implementation and add the following line to the HandleWorkerConnectionEstablished method.

GameObjectCreationHelper.EnableStandardGameObjectCreation(Worker.World, entityRepresentationMapping);

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

This adds the GameObjectInitializationSystem with an instance of the GameObjectCreatorFromMetadata class to your worker, and pass along the selected prefab mapping for that worker type.

(Optional) Link a worker prefab to your worker instance

If you have a worker prefab that you wish to link to your worker instance, you should replace the line noted above with:

   GameObjectCreationHelper.EnableStandardGameObjectCreation(Worker.World, entityRepresentationMapping, workerPrefabInstance);

GameObject Creators

The other component of the GameObject Creation Feature Module is the GameObject Creators. These describe how to spawn a prefab in the world.

The GameObjectCreatorFromMetadata class is the default implementation for spawning GameObjects for your SpatialOS entities.

Updated about a year ago

Set up basic spawning

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.