Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question [MLAPI] Simultaneous work as a server and as a client.

Discussion in 'Multiplayer' started by Balphagore, Nov 4, 2021.

  1. Balphagore

    Balphagore

    Joined:
    Jul 18, 2019
    Posts:
    81
    Is it possible to make the project in one instance the client, and in the other the server? For example, there is a master server, game servers, and regular clients. So the game server will be a client for the master server and a server for regular clients. Didn't find a way to implement this, since NetworkManager is a singleton and cannot be in two states at the same time.

    If you edit the NetworkManager code and remove its declaration as a singleton, then technically it is possible to run two NetworkManagers in different states, but then other package files start giving errors, since they access NetworkManager through its singleton, which is no longer in such a situation.

    Is there any option to implement this? The idea is for the master server to act as a hub, to which both clients and game servers connect to find each other, and then connect directly. Is it possible to implement this now using only MLAPI? Or do i need to use another solution?
     
  2. DiegoSynth

    DiegoSynth

    Joined:
    May 12, 2019
    Posts:
    8
    Nobody answers in this forum or in any Unity group. The community seems to be super cool... maybe they are in a freezer.

    I'm also trying to start with multiplayer, asked about separated client and server and obviously got no reply.
    From what I've seen, MLAPI (now NetCode) would be really limiting me regarding the way I'd like to structure things. You basically have to make remote calls among others, and adapt yourself to the genius decisions they've taken arbitrarily which totally block the way (like the singleton you mention).

    To make it short, I found that you can also use Unity Transport, which is a lower level layer (I guess NetCode is written on top of that). With that API you can basically handle client server connections as a normal human being and decent designer + programmer.
    I suggest you take a look at it:

    Workflow: Creating a minimal client and server | Unity Transport | 0.3.1-preview.4 (unity3d.com)

    (beware, if you copy paste the server / client code, the IDE (Visual Studio in my case) will throw errors as they wrote a line of code wrongly (the call to BeginSend). If you need help with that, let me know.

    So I hope you find this useful!
    Regards,

    Diego