I made a setup with a server and a client.
When initializing the server and connecting with the client, both spawn a player. The following code snippet belongs to a script which is attached to the local camera, which does not have a NetworkView component (It seems that it is not needed when instantiating prefabs over the network):
void OnServerInitialized ()
{
SpawnPlayer ();
}
void OnConnectedToServer ()
{
SpawnPlayer ();
}
void SpawnPlayer ()
{
Network.Instantiate (cubeprefab, transform.position, Quaternion.identity, 0)
}
When any player is killed the following RPC is called. This RPC resides within the movement-script of the player prefab:
[RPC]
public void TakeDamage ()
{
if (networkView.isMine)
Network.RemoveRPCs (networkView.viewID);
Network.Destroy (networkView.viewID);
Camera.mainCamera.GetComponent<NetworkScript> ().SpawnPlayer ();
}
}
Everything is working fine except for one thing. When the server-player gets killed, The buffered Network.Instantiate gets deleted by calling Network.RemoveRPCs (networkView.viewID); in the TakeDamage method.
When the client is killed it is not.
Since both players correctly return true when checking networkView.isMine I assume that each player instantiates the prefab for himself.
2. Test: Killing the server-player after the client-player did not remove it’s Instantiate, the server too is not deleting that, which means he is not holding that RPC.
3. Test: When instead of trying to remove the RPC via Network.RemoveRPCs (networkView.viewID) I try to do the same thing via Network.RemoveRPCs (Network.player, 0), it works.
Conclusion: The RPC seems to belong to the instantiating player, but can not be adressed by the viewID.
My question is now: where does the buffered Network.Instantiate for the client go if not to his viewid and how can I delete it without using groups?