Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Question Separated server code from client code

Discussion in 'Multiplayer' started by Nephthys, Oct 2, 2022.

  1. Nephthys


    Dec 30, 2015

    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!
  2. CodeSmile


    Apr 10, 2014
    Unity has a dedicated server platform build target:

    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.
  3. Punfish


    Dec 7, 2014
    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 can automatically strip server code in builds by the way.
  4. ilyes-garifullin


    Jan 2, 2014
    Sorry, but yes, you need to separate server code from client. It’s bad idea to keep server code on client for many reasons.
    Karabin likes this.
  5. CodeSmile


    Apr 10, 2014
    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.
    MrBigly likes this.