Before reading this document, make sure you are familiar with:
To define an entity template, you must first construct an
var entityTemplate = new EntityTemplate();
EntityTemplate can be mutated and used multiple times.
All SpatialOS entities require the
EntityAcl component is automatically handled by the
EntityTemplate class. This component determines which types of workers have read access to an entity and, for each component, which type of worker can have write access. Note that at any point in time, only instance of a worker can be authoritative over an entity's component.
Note: See the documentation on standard schema library componentsn for more information.
To add components to the entity template and specify which worker type has write access over the component, use the
// Adds the Position component to the template and specifies that // only a UnityGameLogic worker can have write access entityTemplate.AddComponent(new Position.Snapshot(coords), "UnityGameLogic");
AddComponent method updates the write access attribute for the given component in the
To ensure that interested workers can read the components and values of an entity, the read access must be set in the
This is done by calling the
// Ensures that any UnityGameLogic and UnityClient worker can read all components on an entity entityTemplate.SetReadAccess("UnityGameLogic", "UnityClient");
In addition to adding components and setting read access, the
EntityTemplate class provides other utility methods for:
- getting, overriding or removing component snapshots from the template
- getting or overriding component write access attributes for a given component in the template
- creating an
Entityinstance from the template
You can find more information about these methods in the API reference documentation.
Updated about a year ago