- Home /
Starting multiplayer architecture.
I am working on a new 3d game based on a 2D tiled map. After developing the most basic features (procedural map generation, and player movement) i want to make it work in multiplayer.
I have read the whole HLAPI documentation and I have done twice the HLAPI tutorial [link al tutorial] , but my current architecture seems pretty different to the architecture shown in the mentioned tutorial.
This is how the game works without multiplayer:
Pregame Scene objects:
An empty object with an script called "GlobalController", this will be alive through all scenes taking care of scene management and as global data storage.
Another empty with an script called "PregameUIController", this will take care about the user interaction with the pregame scene.
A Canvas an other irrelevant objects.
Pregame scene main flow:
The global controller load from files the game definitions (types of tiles, types of biomes, types of entities)
The player select the size and seed of the planet and click play
The global controller creates a new planet(c# class, not monobehaviour, only for data storage) prepared for creation
The global controller changes the scene to planet creation scene
Planet creation Scene objects:
Planet creation controller, taking care of planet creation and displaying the user the current state of the planet creation.
Planet creation main flow:
Planet creation controller (PCC from now) get the reference to the planet from the global controller
PCC creates the planet terrain and entities while telling the state of the process to the player
PCC sets the starting position of the planet based on a complex algorithm
PCC tells Global controller to start playing the planet
Global controller creates a new Player (c# class, not monobehaviour, only for data storage) as activePlayer, which will contain the starting position of the player
The global controller changes the scene to playing scene
A Canvas an other irrelevant objects.
Playing scene objects:
Render controller, taking care of what is showed on the player screen
InputController, taking care of the player inputs
PlayerController, taking care of the player prefab and his different behaviours
A Canvas an other irrelevant objects.
Playing scene main flow:
Render controller and player controller gets the planet and players references from global controller
Render controller render the nearest chunks to the player
Player controller instantiate the player prefab
Input controller manages the input to ask playerController move the player + Moving the player consists in: + player controller verify the destination is a valid destination + playercontroller asks playerObject (monobehaviour attached to the playerPrefab) to move + when movement ends, playerObject modify the player position
This is what i try to achieve
Pregame scene:
The user decide if play as host or client + If client go to planet creation scene + If host set seed, size and other parameters and then go to planet creation
Planet creation scene:
If host, procede normally (lets create the planet while notifying the player, then create the player, finally go to main scene)
If client: + Get the planet data from server + Global controller creates a new Player as activePlayer, which will contain the starting position of the player. (Same as before)
Playing scene:
Both players can move and see the other movements in the same map (which currently is not being modified)
Player controller can verify if a player can move to the next tile (local verification)
When PlayerPrefab starts moving, the server is notified, if it is an illegal movement server notifies back and movemet is aborted.
The problems:
Making the planet only to be generated (complex perlin algorithm) on the server.
Sharing the planet info (custom class that contains more custom classes) with the client when he connects?
Making the controllers (Global controller, Network controller, ...) extend from NetworkBehaviour and assign them a NetworkIdentity then, as said in the documentation, them will be deactivated till the scene is loaded preventing to sync the data of the controllers from server to client.
Avoiding the playerPrefab to spawn while I still have not the need info to spawn it (even I am not in the playing scene).
THE QUESTIONS:
Do I need to refactor the whole game to change how things communicate with each others? If you think I can stick to this architecture, can you give me some guidelines to make this work.
Your answer
![](https://koobas.hobune.stream/wayback/20220612135251im_/https://answers.unity.com/themes/thub/images/avi.jpg)