Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Rpc function "RpcDamage" called on Client Error

Discussion in 'Multiplayer' started by LiOn0X0HeaRt, Jun 24, 2015.

  1. LiOn0X0HeaRt

    LiOn0X0HeaRt

    Joined:
    Jul 14, 2014
    Posts:
    38
    Hi
    what does this error mean?
    Rpc function "RpcDamagePlayer" called on Client
    code

    Code (CSharp):
    1.     [ClientRpc]
    2.     void RpcDamagePlayer(GameObject hittedPlayer,Transform hitter)
    3.     {
    4.    
    5.    
    6.         //hittedPlayer=    hittedPlayer;
    7.  
    8.  
    9.         if(!isLocalPlayer){
    10.         Debug.Log(hittedPlayer.name);
    11.         hittedPlayer.GetComponent<PlayerGetHit>().Damage(transform.forward);
    12.         }
    13.    
    14.         //    hittedPlayer.GetComponent<PlayerGetHit>().curHealth -=10;
    15.    
    16.     }
     
    Last edited: Jun 24, 2015
  2. LiOn0X0HeaRt

    LiOn0X0HeaRt

    Joined:
    Jul 14, 2014
    Posts:
    38
    I would like to add that it works as its supposed to
    but i just keep getting this error
    is it a bug?
     
  3. cblarsen

    cblarsen

    Joined:
    Mar 10, 2007
    Posts:
    266
    Hmm. Since the error is not complaining about the RpcDamagePlayer function, but about the RpcDamage function, I think that maybe the RpcDamage function is elsewhere?

    Looks to me like the PlayerGetHit.Damage() function might be calling a function called RpcDamage, which was only supposed to be called on the server?
     
  4. LiOn0X0HeaRt

    LiOn0X0HeaRt

    Joined:
    Jul 14, 2014
    Posts:
    38
    Sorry i forgot to type the full name
    RpcDamagePlayer on bboth
     
  5. LiOn0X0HeaRt

    LiOn0X0HeaRt

    Joined:
    Jul 14, 2014
    Posts:
    38
    Can someone explain to me why is this error occurring ?
     
  6. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
    need more details to answer this.
     
  7. GixG17

    GixG17

    Joined:
    Aug 18, 2013
    Posts:
    105
    usingUnityEngine;
    usingUnityEngine.Networking;
    usingSystem.Collections;

    public class ChatBox : NetworkBehavior {

    private void SendChat(string message)
    {
    if (isServer) {
    Rpc_ChatMessage(message);​
    } else {
    Cmd_ChatMessage(message);​
    }​
    }

    [Command]
    private void Cmd_ChatMessage(string message)
    {
    Rpc_ChatMessage(message);​
    }
    [ClientRpc]
    private void Rpc_ChatMessage(string message)
    {
    Debug.Log(message);​
    }​
    }

    What happens is that whenever the function SendChat is called, the server gets an error stating "Cmd function is called on server". The problem is that it shouldn't be sending a CMD at all. If I do host a server and follow that up with SendChat, I get a "Rpc function is called on client", instead.
     
    Last edited: Jul 11, 2015