Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Network.RemoveRPCs does not remove Network.Instantiate on Client

Discussion in 'Multiplayer' started by hexagonius, Mar 26, 2013.

  1. hexagonius

    hexagonius

    Joined:
    Mar 26, 2013
    Posts:
    98
    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):

    Code (csharp):
    1.  
    2. void OnServerInitialized ()
    3. {
    4.     SpawnPlayer ();
    5. }
    6.  
    7. void OnConnectedToServer ()
    8. {
    9.     SpawnPlayer ();
    10. }
    11.  
    12. void SpawnPlayer ()
    13. {
    14.     Network.Instantiate (cubeprefab, transform.position, Quaternion.identity, 0)
    15. }
    When any player is killed the following RPC is called. This RPC resides within the movement-script of the player prefab:

    Code (csharp):
    1. [RPC]
    2. public void TakeDamage ()
    3. {
    4.     if (networkView.isMine)
    5.         Network.RemoveRPCs (networkView.viewID);
    6.         Network.Destroy (networkView.viewID);
    7.         Camera.mainCamera.GetComponent<NetworkScript> ().SpawnPlayer ();
    8.     }
    9. }
    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?
     
    Last edited: Mar 26, 2013
  2. MylesLambert

    MylesLambert

    Joined:
    Dec 31, 2012
    Posts:
    61
    Did you find a solution to this? I was running into the same issue :(
     
  3. ptz4ever

    ptz4ever

    Joined:
    Nov 2, 2012
    Posts:
    5
    Sombody has any solution for it?
     
  4. hugettini

    hugettini

    Joined:
    Apr 1, 2013
    Posts:
    19
    Bum, same problem here!
     
  5. 00Fant

    00Fant

    Joined:
    Mar 10, 2015
    Posts:
    131
    i write my own NW.Instantiate. this solve the problem. but u must set the netwerkview ID.
    [RPC] void MyNetworkInstantiate( ....

    with this u can remove the RPC´s. after killing the Player ( removing )

    sry for my bad english but i hope it helps.