Search Unity

  1. Check out the Unite LA keynote for updates on the Visual Effect Editor, the FPS Sample, ECS, Unity for Film and more! Watch it now!
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

RPC and CMDs not getting fired, script has local player authority but doesn't have authority?

Discussion in 'Connected Games' started by Thimble2600, Jul 10, 2018.

  1. Thimble2600


    Nov 27, 2015
    Having some trouble with authority.

    In my canvas I've 2 UI elements. A chat window which is an image with some text on top for username and message. The image scrolls to the left over time. The other UI element is an input field.

    The chat has a chat class which I've posted some methods of below.

    The objective is simply: A player types a message, hits enter which fires ClientSide() which calls CmdSendMessage() which calls RpcSendMessageToClients().

    This works for the host but not for connecting clients. Connecting clients get the message "Trying to send command for object without authority." which directs me to
    in the ClientSend method.

    The chat class (which again has all the code seen below) has local authority.

    I think this code was working yesterday, so why it's not working now I have no idea. If anyone can shed some light on what I'm doing wrong I'd be very grateful.

    Code (CSharp):
    1. public void ClientSend()
    2.     {
    3.         if(isClient)
    4.         {
    5.             if(m_chatInputField.text.Contains("\n"))
    6.             {
    7.                 CmdSendMessage(m_chatInputField.text);
    8.                 m_chatInputField.text = string.Empty;
    9.                 m_chatInputField.DeactivateInputField();
    10.             }
    11.         }
    12.     }
    14.     [Command]
    15.     void CmdSendMessage(string message)
    16.     {
    17.         //execute on server
    18.         m_message_message.text = message;
    19.         rTransform.position = startPosition;
    20.         timer = interval;
    22.         RpcSendMessageToClients(message);
    23.     }
    25.     [ClientRpc]
    26.     void RpcSendMessageToClients(string message)
    27.     {
    28.         //execute on client
    29.         m_message_message.text = message;
    30.         rTransform.position = startPosition;
    31.         timer = interval;
    32.     }
    Last edited: Jul 10, 2018
  2. hottabych


    Apr 18, 2015