I am working on a multiplayer concept for a 2d game with many small dungeons connected via a world map featuring many floors with many small rooms.
I am thinking on how to design such a setup with NFGO. Physically separating the rooms is not feasible because of the different scales (world map and dungeons). The server machine spinning up an extra unity instance per room seems like overkill and also introduces the challenge of inter process orchestration of the rooms which is complicated.
My vision is now to have only one server unity instance for the whole game. For each room the server instance would create a separate network manager where the clients in that room would connect to. In addition the server would have a separate physics scene per room so object from different rooms would not interfere.
Is this a feasible setup for a micro room game built with NFGO? Is it even possible to have multiple Network Managers in the same Unity instance (provided that they are never accessed via the singleton or course)?
I"m not sure on having multiple network managers. A simpler but not that simple option would be have your own custom scene management where the world map and each dungeon are separate scenes on the client and the server moves the players into and out of them as necessary.
I don’t think you can have multiple network managers but give it a try. At a minimum they would all have to run on a different port so the data is sent to the corresponding manager.
You’ll have a big issue with moving clients between those network managers, they would essentially disconnect from one and connect with another, and you’d have to have a way to persist their data (server can handle this of course).
I tend to think NGO isn’t made for that kind of scenario, or you’re approaching it the wrong way. You probably will get farther if you design this with additive scene loading and separating the scenes in virtual space so there isn’t any overlap (or ensure overlap causes no issues with collisions and all that). The server handles adding scenes (a client enters a dungeon) and unloading them (last client in that dungeon left).
Thanks for you replies. Separating the scenes by virtual space would be by far the easiest approach i guess. Overlapping scenes also is a very interesting thought since it would scale very well but rather difficult to implement.
I will evaluate in both directions.
I came here to ask a similar question. In other solution you can have many users connect and separate them out by some logic. Like load an additional copy of the scene and put them in that scene and then only replicate their network stuff to other clients within that same scene.
So if you have a 3v3 game, you can stick 6 people in a scene and as more games start you just create more scenes.
But here it seems the solution would be to spin up another Unity instance?
There’s nothing to stop you running multiple games in one, as much as server load allows and keeping in mind Netcode touts itself as being for small scale multiplayer solutions.
I would say as someone trying to achieve that goal, do yourself a favour and spin up multiple instances :). There’s a lot of complexity involved and it isn’t that scalable.
Have you tried this? I’m curious what kinds of problems you ran into?
It just makes very little sense to me to launch 100 unity instances to be able to support many players. Just the memory overhead on that will be huge.
Right now I’m kinda leaning to using litenetlib in Unity, and then build a .net server also running litenetlib and do the server logic that way. But not sure if that’ll turn out to be a huge mistake.
For the actual issues there’s a fair amount of work involved in the scene management tracking which objects and players are spawned into each scene, and untangling the client should they drop out at any time. The game has to be structured differently in that you have to think about what classes are game specific and what classes need to shared across all games, I have a whole load of singletons I need to do something about.
I’ve not done any sort of load testing, but for theoretical issues as the server’s running on a single thread, how many games will it be able to support, what parts need to the most attention to optimisation, what parts do you multi-thread. Another concern is if the server crashes it brings all games to an end. I’m not attempting to catch exceptions at least not at the moment, but a lot of Netcode exceptions are fatal and followed by endless spam.
With some experience maybe it’s not so difficult but as I’m making it up as I go along I’d say it’s not for the faint hearted. There’s a lot of chore work that needs to be done which takes away from the more fun element of writing the actual game. You’re pretty much doubling the work load following this approach and it saps my enthusiasm at times. This was meant to be a pretty simple game but already has over a thousand classes and I’m nowhere near done. That of course might just be down to me and my approach.