Search Unity

Question [MLAPI] Distinguish between Client and Server when Hosting

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

  1. PeterPursuit


    Jan 30, 2017
    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


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


    Sep 30, 2020
    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.