4. Deployments and the Runtime
SpatialOS hosts your games for you. In SpatialOS, an instance of a running game is called a deployment. In a deployment, SpatialOS starts the server-worker instances for you, running them in the cloud or on a bare-metal machine. You don’t need to interact with the server-worker instance directly. The game’s client-worker instances connect to the deployment.
Image: A SpatialOS deployment, with connected server-worker and client-worker instances
Because each client-worker instance is tied to a player, and runs on the player’s local machine, SpatialOS doesn’t manage a client-worker instance’s workload in the same way as it manages a server-worker instance’s workload. This means that during game development, you set up client-worker types and server-worker types differently. The main difference is around how you synchronize data to and from the game world.
Like server-worker instances, client-worker instances can only see a part of the world. However, client-worker instances can see across server-worker instance boundaries. SpatialOS uses an efficient and flexible interest management system to determine what a client-worker instance can see. This system is fully integrated with Unreal Engine’s networking API.
Image: A client-worker instance can “see” nearby entities, regardless of the boundaries between server-worker instances
SpatialOS hosts the server element of your multiplayer game. You set up the server hosting via SpatialOS deployments.
In production, you always use cloud hosting, but during development you can test your game with both cloud hosting and local hosting (where your development machine emulates cloud hosting).
You decide how many server-worker instances your world needs, and how to organise them across the world. Server-worker instances are often known as servers. In a deployment, SpatialOS starts those server-worker instances for you, running them on machines in the cloud.
SpatialOS also mediates client-worker connections. Client-workers are often known as clients.
You don’t need to interact with the machines directly, SpatialOS orchestrates the server-worker instances for you. However, you can monitor and manage your deployments with SpatialOS tools. SpatialOS provides an extensive range of tools, including the Inspector which allows you to view what’s happening in a SpatialOS game world in real time.
The SpatialOS Runtime manages your game world. There is one Runtime instance for every game deployment. It includes an entity database that holds the canonical store of all SpatialOS entity data. The Runtime determines which server-workers have authority to update entities in the game world.
Each server-worker and client-worker only receives updates about the part of the game world that it is allowed to receive updates about. The Runtime controls which workers receive which updates.
Your worker instances don’t communicate with the entity database directly. Instead, when a worker instance wants to make a change to an entity, it sends that request to the Runtime. The Runtime then forwards the request to the entity database on the worker instance’s behalf.