Search Unity

  1. The 2022.1 beta is now available for testing. To find out what's new, have a look at our 2022.1 beta blog post.
    Dismiss Notice

Help Wanted [MLAPI] Distinguish between Client and Server when Hosting

Discussion in 'Netcode for GameObjects' started by PeterPursuit, May 25, 2021.

  1. PeterPursuit

    PeterPursuit

    Joined:
    Jan 30, 2017
    Posts:
    1
    Hello there! I can't get my head around the following situation. Hopefully someone can share some wisdom.

    My scene has a bunch of cubes in it with the same movement script on each cube. The script checks if IsOwner == true and then gets Key Input to move the cube. By default all cubes are owned by the server. The server then gives each client ownership of one (or more) cubes. In each instance of the game where I connect as a client I can move around those cubes with given ownership. In the host instance I also move all cubes that are owned by the server. Well, kinda makes sense since a host is client and server at the same time.

    So the question is how do I run client only code and server only code when I'm hosting? Does this even make sense or am I approaching it wrong?
     
  2. Noobassaurus

    Noobassaurus

    Joined:
    Jan 28, 2021
    Posts:
    3
    i might be completly wrong cause i dont really know what im talking about but have you tried isLocalPlayer?
     
  3. luke-unity

    luke-unity

    Unity Technologies

    Joined:
    Sep 30, 2020
    Posts:
    254
    IsOwner should only be true on the owner client, so if you give ownership to a specific client only that client should be able to move.
     
unityunity