Search Unity

Question Separated server code from client code

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

  1. Nephthys

    Nephthys

    Joined:
    Dec 30, 2015
    Posts:
    1
    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!
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,005
    Unity has a dedicated server platform build target: https://forum.unity.com/threads/uni...tions-now-live-please-share-feedback.1143734/

    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

    Punfish

    Joined:
    Dec 7, 2014
    Posts:
    401
    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 https://assetstore.unity.com/packages/tools/network/fish-net-networking-evolved-207815
    FishNet can automatically strip server code in builds by the way.
     
  4. ilyes-garifullin

    ilyes-garifullin

    Joined:
    Jan 2, 2014
    Posts:
    3
    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

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,005
    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.