Sending RPC's to Server as Server

At the moment, I’m having a hard time getting a server to respond to RPC calls that it sends to itself. Why have the server send RPC’s to itself? Because it’s not a dedicated server, and I’d like to consolidate as much of the player code into unified components as possible, that will work whether it’s a client or a server.

def Update ():
	h = Input.GetAxisRaw("Horizontal")
	v = Input.GetAxisRaw("Vertical")
	networkView.RPC("SendUserInput", RPCMode.Server, v, h)

def SendUserInput(v as single, h as single):
	Debug.Log("Got input as: " + v + "	" + h)

At the moment, this code isn’t registering anything on the debug log, even after the server has been set up properly.

I agree it seems wrong, but that’s how Unity does it. You’ll have to test if you’re the server (Natwork.isServer) and call the function directly.

It is very nice to be able to send RPCs to yourself. It’s to bad that Unity networking does not support this.

When we created uLink, a network engine that replaces the Unity network, we made it possible to send RPCs to yourself. This makes the network code much nicer and cleaner.

Please check out the powerful features uLink has that Unity does not, and especially take a look at how easy it is to migrate from Unity Network to uLink via the two-click converter.



in place of:

networkView.RPC (name, RPCMode.Server, args);

Described in some detail here