Get SpatialOS



Workers: How to represent a worker as a GameObject

This document relates to the MonoBehaviour workflow.

Before reading this document, make sure you are familiar with:

Not only can you represent SpatialOS entities with GameObjects in a Scene by creating the SpatialOS entity first, then linking it to a GameObject in a Scene, you can also represent a worker with a GameObject in a Scene.

By representing a worker as a GameObject, the worker can send SpatialOS component commands and world commands even when the worker has no SpatialOS entities checked out.

To represent a worker with a GameObject, you use the Creation Feature Module. Find out how the module works in the documentation on The Creation Feature Module.

To represent a worker as a GameObject: 1. Create a GameObject in your Scene.

  1. Pass the GameObject into the Creation Feature Module using the following methods:

    • If you are using the default implementation of GameObjectCreationHelper.EnableStandardGameObjectCreation(Worker.World, YourWorkerGameObject) if you use the default implementation.
    • GameObjectCreationHelper.EnableStandardGameObjectCreation(Worker.World, new YourEntityGameObjectCreator(), YourWorkerGameObject) if you customized the IEntityGameObjectCreator where YourWorkerGameObject is the GameObject that should represent your worker.
  2. When your game runs, the Creation Feature Module attaches a GameObject component called SpatialOSComponent to the GameObject representing the SpatialOS entity.

  3. Note that the SpatialEntityId field of the SpatialOSComponent is set to 0.

  4. See the documentation to find out more about the SpatialOSComponent.

The GameObject representing your worker is not automatically destroyed when you disconnect from SpatialOS.

Search results

Was this page helpful?

Thanks for letting us know!

Thanks for your feedback

Need more help? Ask on the forums