RPCMode.Server

So I ran a little test to look into how Unity behaves when you send a RPC from the server to itself, using RPCMode.Server.

My code:

<On Click Gui Button:>
networkView.RPC( "MyTestRPC", RPCMode.Server );

@RPC
function MyTestRPC()
{
   Debug.Log( "Received test RPC" );
}

What I expected: the Unity networking layer detects that I’m trying to send an RPC to myself and simply calls the function locally, printing “Receiving test RPC” in the console

What I observed: I get a message “Sent RPC call ‘MyTestRPC’ to all connected clients” in the console but it’s not followed by the “Received test RPC” debug print

If I connect a client and trigger the same RPC call, it works fine and I get the debug message on the server instance. When I try to trigger it from the server itself, it still doesn’t print the debug message to itself.

As far as I can tell, I have everything setup correctly. Is this behavior by design? If so, it’s quite annoying because it forces me to make special case when sending RPCs with RPCMode.Server from the player who acts as a listen server instead of a regular client. ie:

if( Network.isServer ) 
   MyTestRPC()
else
   networkView.RPC( "MyTestRPC", RPCMode.Server );

Is there any way around this? Or am I doing something wrong?

Unfortunately you are not doing anything wrong.

I ran into this a while back and had to write a special case for it too.

Another thing you may run into is that you can not send from client to client. This is hard to detect when you are just testing with 2 computers since the 2 can always send to eachother. But when you add that 3rd computer on, you would notice it.

Yes this is exactly right and I too had to do this work around. The good thing is the following works:

if( Network.isServer )
playerenteredgameroomRPC(playerone);
else
networkView.RPC ("playerenteredgameroomRPC", playerone);

That is you can call and RPC function locally.

I am going to guess that the lack of a call to the server from the server with RPCMode.Server is an intended behavior.