Separated server code from client code

Hey,

I’d like to build a 3d multiplayer game (eg.: tower defense).
I will need my server and client separated. So that i have 1 server project which contains only the logic, handles the incoming requests and answers them.
Also i will have 1 client project which handles the ui interactions, sends these to the server, then processes the responds.

With which asset/library and what technology could i achive communication between server and client?
Also is it necessary for my server to be made in unity?
Are there any best practices for structuring my scripts?

Thank you in advance!

Unity has a dedicated server platform build target: Unity 2021.2: Dedicated Server target and stripping optimizations now live! Please share feedback!

So you do not need to create separate projects.

For tech you can use just about anything, Mirror, Photon, Unity’s new Netcode for GameObjects, … and depending on that and how much convenience features you can live without you could have a server that’s not made in Unity.

Based on the type of question I’d say you should first make a simple prototype with networking and learn by doing. You’ll realize it’ll be much, much harder to just get some things interacting in a network. Once you know how all of this works, you can scrap your prototype and start fresh and that’s when you make choices regarding what the server is doing, how it is being programmed, etc.

I agree with CodeSmile that you need to first decide if you need a unity server. If your game will store states on or have interactions between GameObjects, especially physics, you probably need a unity based server solution.

If you aren’t using a unity server I recommend LiteNetLibManager.
Otherwise, I recommend FishNet FishNet: Networking Evolved | Network | Unity Asset Store
FishNet can automatically strip server code in builds by the way.

Sorry, but yes, you need to separate server code from client. It’s bad idea to keep server code on client for many reasons.

1 Like

You can achieve code separation without having to use separate projects. In fact, you HAVE to use one and the same project for NGO to work due to different projects generating different asset GUIDs / net IDs.

1 Like