Unity-Technologies / com.unity.netcode.gameobjects

Netcode for GameObjects is a high-level netcode SDK that provides networking capabilities to GameObject/MonoBehaviour workflows within Unity and sits on top of underlying transport layer.
MIT License
2.15k stars 435 forks source link

How to implement replicas in MMO? That is, some players enter another scene without affecting other players #2880

Open 9death opened 7 months ago

9death commented 7 months ago

How to implement replicas in MMO? That is, some players enter another scene without affecting other players

Jayson-Furr commented 2 months ago

This is something I am working on now. So, here is how I see it and am planning to implement this. I plan to make each zone a scene. The scenes will have static content of the zone. I plan to create a boot manager that will determine if the instance is server or client and add the corresponding boot manager to the active boot scene.

If the instance is a server, the server boot manager will load the server configuration, the address, the port, the scene name / zone name, the backend credentials, etc. At this point, it will start the server and travel to the correct scene / zone, awaiting connections.

The server will then instantiate all the network objects for that zone based on data it pulls for the objects, NPCs, etc. from a backend like Cloud Save.

When a connection is established, the server will validate credentials and the players right to be there and either disconnect or approve the connection.

When a connection is approved, the server will load the data for that player and their location and rotation. It will then instantiate the player's character at that location and rotation giving the client's player controller / player prefab control over it.

When the user leaves, the server will update the player data to the backend and destroy the player's character.

If a player wants to move to another scene / zone, the server will save that data to the backend and send an RPC to that client that will then disconnect and connect to the other zone / server.

So, each scene / zone, in this case, is a separate server instance. Once the server loads the scene / zone, it never loads a separate scene / zone.

If the instance is a client, the client boot manager will load the menu allowing the user to login and connect to a scene / zone which is just a list of the servers you have online.

Hope this helps you with some ideas...

Thanks, Jayson Furr