Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  4. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  5. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  6. 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

    Thimble2600

    Joined:
    Nov 27, 2015
    Posts:
    34
    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:
    61