This is an attempt to create a dots based multiplayer game using Unity and to learn how to make things to scale. The eventual goal is to re-create Realm of the Mad God, but i am sure you can use this repo to figure out how to do a few of the multiplayer systems.
This top level architecture is inspired from the multiplayer sample project inside the not-yet released unity.transport package. But unlike the ICustomBootstrap
method to initialize the different worlds, we use Zenject based Initialize function to create the server and client worlds. The settings are stored in a scriptable object which is injected into the WorldManager
. The ClientWorld
makes a copy of the InitializationGroup
, SimulationGroup
and PresentationGroup
from the DefaultWorld
. The PresentationGroup
is added only if you're the "user" and not a bot. You can set clientCount
to spawn multiple clients. The ServerWorld
makes a copy of InitializationGroup
and SimulationGroup
. Custom worlds cannot call update on their systems so these custom world systems are added back to the DefaultWorld
systems update cycles.
LiteNetLib is used to create the server and client network peers and are completely contained in the ClientNetworkSystem
and ServerNetworkSystem
. Communication with and to these systems is done through custom component data objects in their respective worlds. We use MessagePack-CSharp to serialize the data between the worlds. Right now only two objects are exchanged between the clients and server.
- The
ClientInputData
which is the per frame info about the user's input + their input tick. This is sent from Client -> Server. - The
WorldState
which is the snapshot per client (relative to the player input index).
- Generalize the network data from only input data and world state to general rpc objects.
- Send deltas instead of world snapshot.
- Physics, obstacle detection.
- Server side NPCs.
- Diconnect/Re-connect handling.