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?
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.
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)
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.
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.