D
D
DOTSNET
Search…
Server & Client Worlds
DOTSNET creates a ServerWorld and a ClientWorld when starting:

ConvertToNetworkEntity

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.

World Attributes

You can put a system into the server world by using the [ServerWorld] attribute:
1
using DOTSNET;
2
3
[ServerWorld]
4
public class ServerSystem : SystemBase
5
{
6
}
Copied!
You can put a system into the client world by using the [ClientWorld] attribute:
1
using DOTSNET;
2
3
[ClientWorld]
4
public class ClientSystem : ComponentSystem
5
{
6
}
Copied!
A system can also be in both worlds:
1
using DOTSNET;
2
3
[ServerWorld, ClientWorld]
4
public class ServerAndClientSystem : ComponentSystem
5
{
6
}
Copied!
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.

Simulation System Groups

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:
1
using DOTSNET;
2
3
[ServerWorld]
4
[UpdateInGroup(typeof(ServerActiveSimulationSystemGroup))]
5
public class MonsterMovementSystem : ComponentSystem
6
{
7
}
Copied!
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:
1
using DOTSNET;
2
3
[ClientWorld]
4
[UpdateInGroup(typeof(ClientConnectedSimulationSystemGroup))]
5
public class LocalPlayerMovementSystem : ComponentSystem
6
{
7
}
Copied!

Accessing Server/ClientWorld from the Outside

Use the static Bootstrap class to access Server/Client World systems from anywhere in Unity:
1
using DOTSNET;
2
3
public class SomeClass
4
{
5
void Example()
6
{
7
// log the names
8
Debug.Log(Bootstrap.ClientWorld.Name);
9
Debug.Log(Bootstrap.ServerWorld.Name);
10
11
// find the server/client systems
12
Bootstrap.ServerWorld.GetExistingSystem<NetworkServerSystem>();
13
Bootstrap.ClientWorld.GetExistingSystem<NetworkClientSystem>();
14
}
15
}
Copied!
Last modified 5mo ago