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 GameObject 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 GameObject Creation Feature Module attaches a GameObject component called LinkedEntityComponent to the GameObject representing the SpatialOS entity.
    • Note that the SpatialEntityId field of the LinkedEntityComponent is set to 0. This is an invalid SpatialOS Entity ID.

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