Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Server/Client Structure

Discussion in 'Multiplayer' started by davej256, Nov 11, 2022.

  1. davej256

    davej256

    Joined:
    Nov 11, 2022
    Posts:
    16
    Hello. I am looking to design my own netcode for unity. I understand that I should have a single project for the server and client, rather than separating them into two different projects.

    I can think of two ways to do this.

    1.) Single scene:
    - When the client hits "play" inside of the editor, there is only a single scene. The client will be acting as both the player and the server at once. I suppose I would have to do some sort of fake socket connection. I would also have to have different code with a real socket connection for when the game is properly compiled for both the server and client when they are running on different machines. Very messy imo but I believe this is how everyone does it. Please correct me if I'm wrong on how this is done.
    2. ) Multi scene:
    - For this method, I would take advantage of unity's "multi-scene physics". When the client hits "start" in the editor, the current scene will get cloned into a new 2nd scene, which will become the server simulation. The main original local scene is the client simulation. These two scenes will not interact with each other locally. That way I can have a proper socket connection running between both of the scenes without having to do any weird fakery. This will hopefully be easier to debug in the long run and hopefully less confusing spaghetti code as a result.
    I look forward to reading the replies on the proper way to do this.
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,066
    Neither 1) nor 2) make any sense to me.

    Could you tell us what your requirement or goal is?

    "design my own netcode" means what exactly? You want to make a multiplayer game? Or do you want to write your own network transport? If so, why would you feel the need to do that rather than using Netcode for GameObjects or any other networking library and the various transports they provide?
     
    Niter88 likes this.