Server & Client Worlds
Last updated
Last updated
DOTSNET creates a ServerWorld and a ClientWorld when starting:
ECS comes with a ConvertToEntity component that allows us to convert GameObjects to Entities in the Default World.
DOTSNET comes with a ConvertToNetworkEntity component that converts GameObjects to Entities in the Server/ClientWorld:
Most entities will live in both worlds.
For example, a monster would live in both worlds so that the server can move it, then sync the position to the same entity in the client world.
You can put a system into the server world by using the [ServerWorld]
attribute:
You can put a system into the client world by using the [ClientWorld]
attribute:
A system can also be in both worlds:
If a system has no attributes, then it’s only in the DefaultWorld.
DOTSNET entirely operates in the Server/Client world, not in the DefaultWorld.
For convenience, DOTSNET comes with custom simulation system groups.
On the server, you can put a system into the ServerActiveSimulationSystemGroup, so it’s only updated while the server is active (after NetworkServerSystem.StartServer was called, until StopServer is called). For example, monster movement should only be updated while the server is actually active:
On the client, you can put a system into the ClientConnectedSimulationSystemGroup, so it’s only updated while the client is connected to the server (after a successful NetworkClientSystem.Connect until Disconnect). For example, local player movement should only be updated while the client is actually connected:
Use the static Bootstrap class to access Server/Client World systems from anywhere in Unity: