Client's RPC call doesn't excute on server without any error log.

Hello,

I’m trying to implement an authoritative server with my game.

When my client finished loading a level, i want it to call a function in server to notify the server that it has finished loading a level. After receiving RPC call from client, server would do a RPC call on client to spawn a new hero on client. i wrote my code like this: (those 2 functions is on the same script file).

void OnLevelWasLoaded(int level)
	{
		Debug.Log ("OnLevelWasLoaded. level = " + level);
		if (Network.isClient) 
		{
			Debug.Log ("Call OnLevelLoaded on Server");
			networkView.RPC ("OnLevelLoaded", RPCMode.Server, new object[] {networkView.owner});
		}
		else 
		{
			int i = Random.Range(0, spawnSetups.Count - 1);
			spawnInfo spawnSetup = spawnSetups*;*
  •  	SpawnPlayer(spawnSetup.position, spawnSetup.rotation);*
    
  •  	playerCount++;*
    
  •  	playerIPs.Add(networkView.owner.ipAddress);*
    
  •  }*
    
  • }*
  • [RPC]*
  • void OnLevelLoaded(NetworkPlayer player)*
  • {*
  •   Debug.Log ("OnLevelLoaded");*
    
  •   //Call the next step, in this case, spawn new instance of player*
    
  •   int i = Random.Range (0, spawnSetups.Count - 1);*
    

_ spawnInfo spawnSetup = spawnSetups ;_
* networkView.RPC (“SpawnPlayer”, player, spawnSetup.position, spawnSetup.rotation);*
* }*
I don’t have 2 computer so i run 2 unity instances on a same computer, one is the server and other is the client who connects to server with:
Network.Connect(“127.0.0.1”, 25000);
The bug is onLevelLoaded isn’t excuted on server. When testing, i see client has the log:
Call OnLevelLoaded on Server
But on the server, i don’t see the log:
OnLevelLoaded
Server don’t have any error log when testing.
Please help me with this bug. Please excuse my English too :).

Are you sure that you have RunInBackground set to true? Either in the player settings or by setting Application.runInBackground to true in a script. Otherwise the other instance can’t react to any kind of network communication until it got refocused again.

Next thing is you send “networkView.owner” to the server. Are you sure you (the client) actually owns that networkview? NetworkViews that are stored in scenes belong to the server. If you want to send your own NetworkPlayer to the server, use Network.player. However it’s actually not necessary to send the NetworkPlayer manually since that information is available for every RPC. Just add the implicit NetworkMessageInfo parameter as last parameter. It will be “filled” by the system automatically. It also doesn’t increase the bandwidth. See the examples in the manual