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?