Search Unity

  1. Unity 2019.1 beta is now available.
    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. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Unity 2018.3 is now released.
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    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

    Thimble2600

    Joined:
    Nov 27, 2015
    Posts:
    138
    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
    CmdSendMessage(m_chatInputField.text);
    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.     }
    13.  
    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;
    21.  
    22.         RpcSendMessageToClients(message);
    23.     }
    24.  
    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

    hottabych

    Joined:
    Apr 18, 2015
    Posts:
    74