Summary of RPCModes

I have read through the forums searching for a problem with my RPCModes. I have come across a lot of conflicting views on how the RPCModes actually work when called from different machines. So I ran a test to see what machine heard what call when sent from both server and client. Here are my conclusions.

Please note that this test was run on one machine with 3 instances of the game running.

X means that the machine received the message
O means the machine sent the message

  • means the machine heard and sent nothing
RPCMode Server Client 1 Client 2
All OX
X
X
All X
OX
X
Others X
O
X
Others O
X
X
Server O
X
X
Server X
O
-

Conclusions

RPCMode.All sends to everyone, including itself, EVEN ON THE SERVER.

RPCMode.Other does exactly what it implies - it sends the message only to the other machines and not itself.

RPCMode.Server has some interesting methodology though. Server will send to all the clients if called from the server. If called from the client, it will only hear it on the server.

Anyway, I thought people might find this useful. If the results are different for different machines, run a test and post it here, so people know when they search for RPCMode.

Thanks - Dan

Also, if anyone is interested, here is my code.

Here is the update:

void Update()
    {
        string user = Network.isServer ? "server" : "client";
        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            TestConnectionRPC(RPCMode.All, user);
        }
        else if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            TestConnectionRPC(RPCMode.Others, user);
        }
        else if (Input.GetKeyDown(KeyCode.Alpha3))
        {
            TestConnectionRPC(RPCMode.Server, user);
        }
        else if(Input.GetKeyDown(KeyCode.Space))
        {
            TestConnectionRPC(RPCMode.All, "SPACE");
        }
    }

And then the function that is getting called

public void TestConnectionRPC(RPCMode typeIn, string user)
    {
        networkView.RPC("RPCListener", typeIn, typeIn.ToString(), user);
    }

And finally the RPC that is contained in every machine

    [RPC]
    public void RPCListener(string typeHeard, string user)
    {
        string person = "";
        if (Network.isClient)
            person = "client";
        if (Network.isServer)
            person = "server";
        
        //label is a NGUI UILabel object that is contained in the scene
        label.text = typeHeard + " heard on " + person + " and was sent by " + user + ";";
    }