Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Question Build a multiplayer mobile game using Netcode for Gameobjects

Discussion in 'Netcode for GameObjects' started by PedroPaulo95, Mar 23, 2023.

  1. PedroPaulo95

    PedroPaulo95

    Joined:
    Apr 22, 2020
    Posts:
    6
    Hello,

    I've been studying the Netcode for Gameobjects and there is a topic that I can't understand at all.
    Let's suppose I want to create a multiplayer mobile game (Android and iOS) with 5 players in a room to play all together. The Unity documentation says to use if (IsLocalPlayer)... if (IsServer)... etc.
    The question is, if I'm creating a mobile game, it will not have a device as a host, probably I'll need a dedicated server that all the clients will connect to that. The code will have the logic to move, attack, and spawn enemies, and in the end, it will be compiled for mobile devices.

    How can I deploy it in a dedicated server to act just as a Server?
    Would the solution be to take exactly the entire project that is already done and compile it as a dedicated server? Are there no code changes? Will it be exactly the same source code compiled and running on the smartphones that will run on the dedicated server?

    It might be a dumb question but I really don't get it. Can someone help me to understand that?

    Thank you!
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    7,018
    Generally speaking the dedicated server code will be in the same project. Best practices like separation of concerns and using assembly definitions is recommended. Unity has a“dedicated server“ build target. It‘s basically the same workflow as building for Mobile and Windows and other platforms. Some code and assets will be shared, others unique to a platform.
     
    PedroPaulo95 likes this.
  3. PedroPaulo95

    PedroPaulo95

    Joined:
    Apr 22, 2020
    Posts:
    6
    Thanks for your reply.
    I saw you have some videos about Unity. Do you have any videos about this topic? If yes, I'd like to check, it would be useful.
     
  4. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    440
    Hi @PedroPaulo95 !

    This (= dedicated server approach) is one way to do so. The other one is to use a Lobby + Relay server, and let one of the players act as a Host (client + server on same device), which exposes you to cheating.

    What will be compiled for mobile devices is the client (or host) version of your game. The dedicated server will need oto be compiled for the operating system running on yoru server (usually Linux, or Windows)

    You can use Unity Game Server Hosting for that.

    yes, you can compile it as a standalone game for Windows or Linux, or use the Dedicated Server build target if you're on Unity 2021 LTS or higher to get a more optimized build

    It depends how your game is architectured, but in general "no" if you make things right (= let the server handle all server-authoritative parts like changes to NetworkVariables) since day 1.

    Does this help?
     
    PedroPaulo95 likes this.
  5. PedroPaulo95

    PedroPaulo95

    Joined:
    Apr 22, 2020
    Posts:
    6
    @RikuTheFuffs-U

    This cleared up many of the doubts that were in my mind. Thank you so much for that!

    I think it comes with practice and experience working on business projects. Documentations and videos have the simplest explanation, but actually learning best practices comes with time.

    I'm a .NET developer working with desktop, web, mobile apps, APIs, services, etc. But I've been studying games for 1 year more or less, all those concepts are very recent for me. I think with time it gets better.

    However, I would be super grateful if you have good learning content to share (documentation, articles, videos, blogs, anything), especially about Netcode for Gameobjects.

    Thanks again!