Get SpatialOS



Designing components

This page is about the things you need to consider when designing components.

Once you’ve worked out what entities your world will have, the next step is to work out what the components of the entities should be.

Elements of components

Components can have three elements:

  • properties describe persistent values that change over time

  • events describe transient things that have happened to an entity

  • commands describe things that other entities can ask this entity to do

Each component can have many properties, events and commands. For example, an explosive barrel might have the following components:

Component Name Type
Position Coordinates Property: coordinates
FuelContainer FuelType Property: enum
Capacity Property: float
CurrentAmount Property: float
Explosive Explode Command
ExplosiveRange Property: float
HasExploded Property: boolean
Damageable CurrentDamage Property: float
MaxDamage Property: float
Flammable OnFire Property: boolean
CatchFire Event

It’s important that everything that you need to define your entity is stored in components. SpatialOS is a distributed system, running over many machines which may fail at any time, so your entity must be able to be recreated from the components. Any local state stored on a worker can be easily lost.

Writing components

Write up your components in the schema, using the SpatialOS schemalang. This schema is used to generate code that all workers can use to read and manipulate components.

For full details, see the schema documentation.

Was this page helpful?

Thanks for letting us know!

Thanks for your feedback

Need more help? Ask on the forums