Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Unity Multiplayer How to create a one-to-one multiplayer game with Netcode for Gameobjects

Discussion in 'Multiplayer' started by lobador, Nov 14, 2022.

  1. lobador

    lobador

    Joined:
    May 29, 2020
    Posts:
    13
    I am very new to the multiplayer concept and need some insights about creating a one-to-one multiplayer game using Netcode for Gameobjects. As far as I review the documents I can create a server/host/client but what is the correct approach for creating a game like backgammon, chess or clash of clans?
    Just to match 2 players and run the game!

    Is there any example with Netcode for Gameobjects for this?
    or can you kindly give me some guidance?

    Thanks in advance!
     
  2. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    352
    Hi @lobador ! You can definitely create these types of game with Netcode for gameobjects (aka "NGO"). If you want to connect two players you can do it in different ways.

    The most popular/cheaper is using a Relay server + NAT punchthrough whenever possible. You can have a look at setting up a Relay server for your game here.
    If your game becomes competitive-focused in the future (I.E: with ranked games like in League of Legends), you might think of switching to a dedicated server approach using Unity Game Server hosting (more expensive, but also cheater-proof if you code your game properly).

    Does this answer your question?
     
    lobador likes this.
  3. lobador

    lobador

    Joined:
    May 29, 2020
    Posts:
    13
    Hi @RikuTheFuffs-U, many thanks for your prompt response.

    I will definitely have a look at to Relay server + NAT!

    As far as I saw in NGO samples, the only options create a server and then a client.

    to connect two players, is there any sample/walkthrough? Should I create one server and one client for each match? or is this a very early question before reviewing Relay server + NAT, you think? :)

    Thanks again!
     
  4. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    352
    @lobador happy to help!

    Maybe the official documentation + this video would be a good starting point for setting up Relay? If it's the first time you use NGO, I'd also recommend this one. It's the one I used to get started and learn more about the basic concepts behind NGO

    It depends on how you architect your game and how you connect your players. In general, you need one "game" server (which is something different than the "relay" server) and clients connect to it. With NGO you can decide to have one player act both as a server and a client. This type of player is called the "host".

    Every time you start a new match, you need to create an instance of a game server and make the client connect to it. If this sounds complicated, don't worry! Unity services do this for you :D

    We also have a discord server in which you can come and ask questions, if it helps. It's here.

    Does this give you a starting point?
     
    lobador likes this.
  5. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    352
    P.S: just a quick note about the Punchthrough: unfortunately Unity doesn't have an out-of-the-box solution for it, so you'll have to use non official packages / plugins for that
     
    lobador likes this.
  6. lobador

    lobador

    Joined:
    May 29, 2020
    Posts:
    13
    @RikuTheFuffs-U,
    your posts definitely gave me a starting point. at least, now I know how to start.

    Many many thanks again!

    I'll have a research session now :)
     
    RikuTheFuffs-U likes this.
  7. VincentStk

    VincentStk

    Joined:
    Feb 14, 2018
    Posts:
    11
    I have a question,
    After I research about NGO, is it default start a server app instance for a match if I use dedicated server?
     
    Last edited: Dec 28, 2022