Search Unity

What would be easiest way to setup networking, so another Unity client sees the same world as main?

Discussion in 'Multiplayer' started by CptanPanic, Feb 1, 2023.

  1. CptanPanic

    CptanPanic

    Joined:
    Dec 19, 2022
    Posts:
    15
    So would like to have a master server, that maintains all the models, and locations, etc. And then would like to have clients, connect to this server, and get all the models that are loaded, and continously get their locations updated in the local world. Local client would have it's own camera, etc. I have read "https://blog.unity.com/technology/choosing-the-right-netcode-for-your-game" but was wonder if anyone had any suggestions.
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,975
    Suggestions about what exactly? What you describe is in principle possible with any networking solution and depending on what you mean by „maintain“ it‘s even standard behaviour to share the same assets (not: download assets on demand from the server though).
     
  3. CptanPanic

    CptanPanic

    Joined:
    Dec 19, 2022
    Posts:
    15
    @CodeSmile Yes I would client to download all the assets from the server after connecting, and from then on keep all the positions in sync.
     
  4. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,975
    Synching the positions is practically automatic. Downloading assets isn't.

    You may want to read up on asset bundles and consider (or calculate an estimate) how much data you're asking users to download. Downloading said data due to its size - assuming we're talking dozens of megabytes or more - is best done using other means than realtime networking systems like NGO, for example P2P transfer (up/download distributed among users of the game client) or a simple HTTP download (requires server bandwidth to scale with client demand).
     
  5. CptanPanic

    CptanPanic

    Joined:
    Dec 19, 2022
    Posts:
    15
    @CodeSmile, note this will all be restricted to a local LAN, so bandwidth will not be a problem, and clients will be less than 10.
     
  6. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,975
    Okay, in that case you really don't need to download assets from the server. You could simply install the same app to every machine (including server) that has all assets included.

    Note that by default a networked Unity project's builds can decide at runtime whether it's running as the server or a client (or a host, which is a client that also acts as the server). It's actually somewhat more involved to create a separate "dedicated server" app and another for clients. Especially testing is more time consuming in that case because you often need to be making two builds.
     
  7. CptanPanic

    CptanPanic

    Joined:
    Dec 19, 2022
    Posts:
    15
    So that sounds like I can just use "Netcode for GameObjects?" or is there an even more higher level networking in Unity?
     
  8. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,975
    Netcode for GameObjects is Unity's current networking solution. It doesn't get higher-level than this, in fact you can only go lower-level with Unity Transport or "sideways" by booking additional "Unity Gaming Services" for Relay, Lobby, Matchmaking and game server hosting.

    Of course alternative networking solutions exist, Fish-Net being the currently go-to standard for free and open source as it is even more feature rich than today's NGO version. Cannot say anything about Photon other than their services eventually costing money. Mirror is also popular but lagging behind in some areas.

    I would say that for LAN games any free solution is fine if you do not have specific feature requirements. See this feature comparison.