UNET - "Trying to send Command for Object without Authority" (from Player)

I’m getting a “Trying to send Command for Object without Authority.” warning when trying to call a [Command] Method from a script on the Player. It’s the same on the host as on clients.

    public void OnSubmit()
    {
        answer = GameObject.Find("Input Handler").GetComponent<InputHandler>().GetAnswer();

        Debug.Log("has Authority: " + hasAuthority);
        CmdSetAnswer(answer, 42, localPlayerId);
    }

The Debug.Log outputs “has Authority: False”.
I read through a lot of threads but most of the time the problem is calling a command from another GameObject than the Player but for me that’s not the case.

Appreciating any and every help :slight_smile:

EDIT: isLocalPlayer is also false. But the script is definitley on my Player.
EDIT2: Here are 2 Screenshot… I seriously don’t know what I’m doing wrong… SC1 and SC2.

I believe you need to check if isLocalPlayer is true at the start of this method and return if it is false. Otherwise the code on the Player is run by all instances. Example if you are Player1 and there is a Player2 in your scene this script will run for both Player1 and Player2 even though I assume you only want to run it for Player1.

Big Thanks to @niocy for helping me!
The solution is to not set the method to call in the Button inspector but to reference it in the Player script.
In this case I set the Button with an OnClick Listener in the OnStartLocalPlayer() method and go from there.

public override void OnStartLocalPlayer()
     {
         submitButton = GameObject.Find("Main Panel/Bot Panel/SubmitButton").GetComponent<Button>();
         submitButton.onClick.AddListener(delegate { SubmitButtonEvent(); });
     }