Search Unity

Override RPC functions

Discussion in 'Multiplayer' started by BamBam, Apr 2, 2010.

  1. BamBam

    BamBam

    Joined:
    Mar 23, 2010
    Posts:
    8
    Hi,

    due to the fact, that RPC functions have to be known by both sides, server and client, i have created a base class RPCs, which inherits from Monobehaviour and from which i derive my networking RPC classes on server- and client side. Server- and Client classes only override the rpc functions which are of interest for them.

    Example

    Code (csharp):
    1.  
    2. public class RPCs : MonoBehaviour {
    3.    [RPC]
    4.    virtual void ClientFunctionA(){};
    5.  
    6.    [RPC]
    7.    virtual void ClientFunctionB(){};
    8.  
    9.    [RPC]
    10.    virtual void ServerFunctionA(NetworkPlayer p) {};
    11. }
    12.  
    13. public class ClientA : RPCs {
    14.    [RPC]
    15.    public override void ClientFunctionA(){
    16.       //do anything A
    17.    }
    18. }
    19.  
    20. public class ClientB : RPCs {
    21.    [RPC]
    22.    public override void ClientFunctionB(){
    23.       //do anything B
    24.    }
    25. }
    26.  
    27. public class Server : RPCs {
    28.    [RPC]
    29.    public override void ServerFunctionA(NetworkPlayer p){
    30.       networkView.RPC("ClientFunctionA", p);
    31.       networkView.RPC("ClientFunctionB", p);
    32.    }
    33. }
    34.  
    35. //call from anywhere, doesn't Matter
    36. //networkPlayer is definitly valid
    37. networkView.RPC("ServerFunctionA", RPCMode.Server, networkPlayer);
    38.  
    When i do the last call, the RPC Function in the server class is called. This function does two RPC call on the NetworkPlayer, One for ClientFunctionA and one for ClientFunctionB.

    Here comes the problem:
    The first call (ClientFunctionA) arrives in ClientA::ClientFunctionA, but the second call (ClientFunctionB) arrices in RPCs::ClientFunctionB.
    There is absolutely no difference between the inheritance of ClientA and ClientB nor can i see any other problem here.

    Can anyone explain why the first RPC call arrives correctly and the second doesn't?

    best regards
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    RPCs are meant to be unique as they will generate an RPC id to be called.

    Its a wonder that what you have there works at all, cause you should run up an error with the RPC id.
     
  3. BamBam

    BamBam

    Joined:
    Mar 23, 2010
    Posts:
    8
    There is no error...

    so, what you mean is, that i can't override RPC functions?

    In that case the solution is to implement my RPC functions on server- and client side seperatly with the same name?

    I found some more information:
    ClientA is also the class where i connect the client to the server. When i move ClientFunctionB into ClientA, both RPC calls arrive correctly... Is the NetworkPlayer bound to the object, that does the connection to the server?
     
  4. BamBam

    BamBam

    Joined:
    Mar 23, 2010
    Posts:
    8
    Ok,

    i have moved all my RPC functions into the class, where i do the server connect. All RPC calls arrive correctly now.

    regards