Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

SOLVED - Changing GameObject from Clients for all other Clients to see

Discussion in 'Multiplayer' started by nensl, Dec 17, 2017.

  1. nensl

    nensl

    Joined:
    May 30, 2016
    Posts:
    6
    I'm having problems understanding a fundamental concept of Unity Networking.

    I have a GameManager (GameObject) attached with a GameManager Script and a NetworkIdentity.
    I have GameObjects which have a Text GameObject as child.

    So now I want every Client to be able to change the Text GameObject for every other Client to see.
    This happens in the GameManager Script.

    Changing and synchronizing from the Server/Host to the Clients works perfectly.
    But changing it from the Clients doesn't.
    I'm getting this warning: "Trying to send command for object without authority."

    I tried adding NetworkIdentities to the GameObjects but nothing seems to work.

    For my Code:
    (It's a Family Feud Style 4 Player Game)
    If somebody answers a question and it's right the CheckAnswer() Function is called.
    In there I have a Command which forwards some variables to a ClientRpc. Here's the Code.

    Code (CSharp):
    1.     [Command]
    2.     public void CmdSetAnswerOnServer(int questionCounter, int localPlayerId, int points, string answer)
    3.     {
    4.         RpcSetAnswerOnClients(questionCounter, localPlayerId, points, answer);
    5.     }
    6.  
    7.     [ClientRpc]
    8.     public void RpcSetAnswerOnClients(int questionCounter, int localPlayerId, int points, string answer)
    9.     {
    10.         GameObject answerCanvas = GameObject.Find("Main Panel/Mid Panel/Player " + (localPlayerId + 1) + "/Answer " + (questionCounter + 1));
    11.         GameObject answerFieldText = GameObject.Find("Main Panel/Mid Panel/Player " + (localPlayerId + 1) + "/Answer " + (questionCounter + 1) + "/Text");
    12.         GameObject answerFieldPoints = GameObject.Find("Main Panel/Mid Panel/Player " + (localPlayerId + 1) + "/Answer " + (questionCounter + 1) + "/Points");
    13.  
    14.         answerFieldText.GetComponent<Text>().text = answer;
    15.         answerFieldPoints.GetComponent<Text>().text = points.ToString();
    16.         answerCanvas.SetActive(true);
    17.     }
    Appreciating every and any help :)
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    A client can only send a command on a GameObject that client either has authority over or is that client's Player GameObject. If you want a client to be able to make changes to a GameObject that isn't its Player and that it doesn't have authority over, you can send a command on the Player GameObject and then have code on the Player that runs on the host make those changes on the other GameObjects. Alternatively you could have the client send a UNet Message to the host to do the same thing.
     
    nensl likes this.
  3. nensl

    nensl

    Joined:
    May 30, 2016
    Posts:
    6
    Yeah I figured that something like that could be the reason...
    I have 120 GameObjects which can change over the course of the game so even if it works, it won't look neat and tidy so I'm gonna cancel my approach and instantiate the objects while the game is running and spawn them on the Server with NetworkServer.Spawn.

    But thanks for the help! SOLVED!