Search Unity

HLAPI How do I give network authority to an existing object?

Discussion in 'Multiplayer' started by Compressed, May 26, 2016.

  1. Compressed

    Compressed

    Joined:
    Sep 20, 2014
    Posts:
    59
    Hi,

    I am using HLAPI.
    I have a scene where I placed a GameObject. To this game object I attached a script which has one simple function in it

    [Command]
    CmdTest(){...};

    I compile the game and start one instance in the editor and one instance directly from the built .exe file. On one instance I jump into the game as a client+host (client1) and in the other instance i simply connect to the host as a client (client2).
    Completely generic setup.

    Now, when I trigger the CmdTest() function on the client1 who is the client+host. The function executes without any problems (Makes sense since the client1 is also the server).
    Then I try to execute it from the client2, which gives me this: "Trying to send command for object without authority."

    This is because currently on the client2 only the Player prefab controlled by client2 has the authority to execute [Command] functions.

    How do I give this authority to that GameObject with the script on it?
    I do not want to attach the script to the player prefab, i want to keep it on that GameObject.
    I tried to use AssignClientAuthority to assign the client authority to that GameObject, but it says AssignClientAuthority only works on objects which were Spawned during runtime via the network spawn command, but my GameObject already exists in the scene since the beginning, so how do i allow scripts attached to it to execute [Command] functions on it?

    Thanks.