Search Unity

Client Rpc not being called why is this?

Discussion in 'Connected Games' started by FoxCastz, Aug 21, 2015.

  1. FoxCastz

    FoxCastz

    Joined:
    Jun 18, 2015
    Posts:
    71
    Hello, I am still stuck on this issue! I am creating a chat system for my games multiplayer, but for some reason the code comes to a screeching halt at this point. On each player object there is a script called PlayerChat, where the player can type their message and the chatHistory is displayed on the GUI. There is also a pre-instantiated ChatManager Object in the scene that runs a ServerChat script which you are viewing a piece of below. The players type a message and send it on its way via CmdSendMessage, the ChatManager receives the message just fine and moves it to the void ChatUpdate where the message is added onto the chatHistory. BUT here is where the problem occurs, it never does RpcSyncChat(), it simply stops as if it were done....

    Code (CSharp):
    1. public void ChatUpdate(string message){
    2.         Debug.Log ("ChatUpdate() Received: " + message);
    3.         chatHistory.Add(message);
    4.         RpcSyncChat ();
    5.     }
    6.  
    7.     [ClientRpc]
    8.     void RpcSyncChat(){
    9.         foreach(GameObject player in players){
    10.                 Debug.Log ("Syncing Chat");
    11.                 player.GetComponent<PlayerChat>().UpdateChat(chatHistory);
    12.         }
    13.     }
    Now the weird part is that when I do not use a ClientRpc call like this:
    Code (CSharp):
    1.     void SyncChat(){
    2.         foreach(GameObject player in players){
    3.                 Debug.Log ("Syncing Chat");
    4.                 player.GetComponent<PlayerChat>().UpdateChat(chatHistory);
    5.         }
    6.     }
    Then the host will receive the messages just fine! It will display the hosts AND the clients messages to the host, but the clients have an empty screen and receive no messages. Please help T.T
     
  2. SuperNeon

    SuperNeon

    Joined:
    Mar 16, 2014
    Posts:
    85
    Hi!

    How the chatHistory is sync on the clients?
    I don't really understand your chat system. Why there is a list of players in the RpcSyncChat ?

    If it is a classic chat system. You have just to care about the new message received and add it in the chatHistory on the server and the clients.

    For the RpcSyncChat issue, the function is never called on the Host ? Your host is a client too or a dedicated server ?
    If it is a host with a client you should received the rpc except if isClient is false.
     
  3. FoxCastz

    FoxCastz

    Joined:
    Jun 18, 2015
    Posts:
    71
    Yes the player is the Host as well as the client, but even when host calls the Rpc it doesn't go through...
     
  4. KungFooMasta

    KungFooMasta

    Joined:
    May 27, 2014
    Posts:
    24
    I am seeing a similar behavior where rpc calls are not working for me.. has anybody seen these working in 5.1.2?

    In my case I have a network object that is spawned to all clients, and this object has a networkbehavior component with an Rpc method, but when I call it from the server, nothing happens. I put a Debug.Log call in there but it just skips is like a no-op...

    Code (CSharp):
    1.         // Called on the server when a client is ready.
    2.         public override void OnServerReady (NetworkConnection conn)
    3.         {
    4.             Log.Add ("Client {0} has signaled it is ready. Unifying HuntInstance GO name and launching HuntDetails UI..", conn.connectionId.ToString ());
    5.  
    6.             HuntManager.Instance.HuntInstance.RpcUpdateGOName ();
    7.             HuntManager.Instance.HuntInstance.RpcShowHuntDetailsUI ();
    8.  
    9.             Log.Add ("HIHIHI");
    Code (CSharp):
    1.         [ClientRpc]
    2.         public void RpcUpdateGOName()
    3.         {
    4.             gameObject.name = "hullabaloo";
    5.         }
    6.  
    7.         [ClientRpc]
    8.         public void RpcShowHuntDetailsUI()
    9.         {
    10.             Log.Add ("HuntInstance.RpcShowHuntDetailsUI()");
    11.             UI_HuntDetails.Instance.Show ();
    12.         }
    In my console output it prints "Client -1 has signaled it is ready..." followed by "HIHIHI". The Rpc functions did nothing at all...
     
  5. FoxCastz

    FoxCastz

    Joined:
    Jun 18, 2015
    Posts:
    71
    I didn't know there was a 5.1.2, I will look into how to download it and see if it fixes anything.

    Edit: It doesn't appear that there are any updates to fix the issue...
     
    Last edited: Aug 22, 2015
  6. Rodolfo-Rubens

    Rodolfo-Rubens

    Joined:
    Nov 17, 2012
    Posts:
    1,097
    BUMP!

    I'm having this same issue in 5.6.0b10!
     
    Last edited: Mar 9, 2017
  7. Rodolfo-Rubens

    Rodolfo-Rubens

    Joined:
    Nov 17, 2012
    Posts:
    1,097
    Bumping this again, I really to know what's happening! I'm calling my commands from a ready player and the commands are working, like the KungFooMasta's codes I also added one debug.log in each method and the Rpc methods are not being executed.
    I can't do absolutely anything because this basic function doesn't work.
     
  8. Rodolfo-Rubens

    Rodolfo-Rubens

    Joined:
    Nov 17, 2012
    Posts:
    1,097
    I figured it out!

    It looks like it takes a "lot" for everything gets ready in all clients (Rpcs only go through after everything is ready for all clients, it seems) so I just started a coroutine in the end of my Start and looped in a while the call for the command I needed (which calls the Rpc I want) and the Rpcs now gets executed.
     
    ruoshan likes this.
  9. warrencwwong

    warrencwwong

    Joined:
    Aug 17, 2018
    Posts:
    16
    Yeah, I agree.
     
  10. ruoshan

    ruoshan

    Joined:
    Jul 14, 2019
    Posts:
    1

    Thanks a lot!!!!!!!!!!!!!!!!