Introduction to workers
Workers perform the computation associated with a simulated world. SpatialOS manages the world, keeping track of all the entities and what state they’re in. But on its own, it doesn’t make any changes to the world. All the logic, all the computation, is done by workers.
Workers connect to your simulated world. They can:
- read the current status of entities in the world
- watch for changes to components
- make changes of their own
For a more in-depth explanation of what workers are, see the workers concept page.
Standard types of workers
Types of workers commonly used in SpatialOS projects include:
Unity is a game engine. SpatialOS provides an SDK so you can easily integrate Unity with a SpatialOS simulated world. As a worker, Unity is commonly used for physics simulation and game logic.
You can also use Unity as a client worker, which players of your game can use to connect to your simulated world.
As workers, Unity clients are normally used to visualize the simulated world, and send player input (like key presses and mouse movements) to SpatialOS for other workers to respond to.
Unreal is a game engine. SpatialOS provides an experimental SDK so you can integrate Unreal with a SpatialOS simulated world. Similar to Unity, Unreal is commonly used for physics simulation and game logic. You can build a worker with Unreal using the experimental Unreal integration.
Similar to Unity, you can also use Unreal as a client worker, which players of your game can use to connect to your simulated world.
As workers, Unreal clients are normally used to visualize the simulated world, and send player input (like key presses and mouse movements) to SpatialOS for other workers to respond to. You can build a client worker with Unreal using the experimental Unreal integration.
You can build a worker in C++, using the C++ worker SDK.
You can build a worker in C#, using the C# worker SDK.
You can build a worker in Java, using the Java worker SDK.
Managed and external workers
Most workers that connect to SpatialOS are managed: the workload of instances of the worker is controlled by SpatialOS, and if an instance becomes overloaded, SpatialOS will start more instances to handle the load.
Game clients, used by players to connect to a game, are an exception. Because each instance is tied to a player, and runs in the player’s machine, SpatialOS can’t manage their workload in the same way. These are external workers.
The work that workers do
The work done by workers includes:
- Get input from the outside world, and write it to a component
- Watch for changes to components
- When something changes,
- Run some logic
- Write to a component
For more information about the kinds of work a worker can do, see the documentation for the worker.
Authority over components
Multiple worker instances can read from a component, but only one of them at a time can write to a particular component.
In order to either read or write from an entity, worker types and instances need to be given access, using an access control list on each entity.
For more information, see Access control lists.
The worker configuration documentation describes where workers live within your SpatialOS application, and how to configure them.
Writing your own worker
Was this page helpful?
Thanks for letting us know!
Thanks for your feedback
Need more help? Ask on the forums