How client call a function on server through RPC?

Hi there,
This is my first question about networking. The idea is after client connecting to server, it calls a “login” function on server and server sends back avatar information.
From client site, after connection, it sends the following RPC request:

function OnConnectedToServer() {	networkView.RPC("ClientLogin",RPCMode.Server,playerName,playerAvatarId);
}

On server side, the RPC function is defined as:

@RPC
function ClientLogin (playername : String, avatarid: int)
{
	var modelname : String = "playerPrefab";
	var pos : Vector3 = Vector3(0,0,0);
	//networkView.RPC("Spawn", info.sender, modelname, pos);
	
	print(playername + " logged in with avatar " + avatarid);
}

The function “ClientLogin” never get called, and I got these errors(on server side):
View ID SceneID: 2 Level Prefix:0 not found during lookup. Strange behaviour may occur

Do I need to setup networkView id for client/server communication? Or I have to use Network.Instantiate?
Which means the RPC funtion doesn’t function by itself, it must adhere to a GameObject instantiated over the network?

Need your advice, thanks!

RPC functions need to be in a component thats placed on an object with an existant network view to work.

Also, although I guess thats known, don’t forget to include the component with the server side rpc in the client build in case you have distinct projects. Otherwise the RPC id for the function is not known and unless that has changed with 2.5, it won’t work

Thanks dreamora, I finally made it work by instantiating a communication prefab from server side and all RPC calls to server go through the networkview attached to this prefab

Great :slight_smile: