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

View ID AllocatedID not found during lookup (Network.Destroy)

Discussion in 'Multiplayer' started by imgodot, Jan 12, 2014.

  1. imgodot

    imgodot

    Joined:
    Nov 29, 2013
    Posts:
    212
    I have a "shot" that is fired from the player.
    The shot is Network.Instantiated from the player.
    The shot has a NetworkView on it.

    When the shot hits something it should be destroyed in OnTriggerEnter.

    When I call Network.Destroy for the shot it **sometimes** gives me:
    "View ID AllocatedID: 152 not found during lookup. Strange behaviour may occur"
    and
    "Couldn't perform remote Network.Destroy because the network view 'AllocatedID: 152' could not be located."

    I've seen a number of posts relating to clearing RPCs, but I am not using RPCs.
    I put RemoveRPCs in anyway to no avail.


    Can someone please help?


    Here is my "shot" script:
    Code (csharp):
    1.     void Awake() {
    2.         if (!networkView.isMine) this.enabled = false; 
    3.     }
    4.  
    5.     void OnTriggerEnter(Collider other) {
    6.         // Exit now if we're hitting another shot.
    7.         if (other.gameObject.name.ToLower().StartsWith ("shot")) return;
    8.  
    9.         // Call the destroy code only if shot and the player have different player #s.
    10.         if (playerNo != other.gameObject.GetComponent<Player> ().playerNo) {
    11.             Debug.Log ("Destroyed");
    12.  
    13.             Network.RemoveRPCs(this.networkView.viewID);
    14.  
    15.             Network.Destroy (this.gameObject);  // ERROR (SOMETIMES), BUT NOT ALWAYS:
    16.         }
    17.     }
     
  2. imgodot

    imgodot

    Joined:
    Nov 29, 2013
    Posts:
    212
    SOLUTION:

    OK, finally found the answer. Geez!
    I had to write the destroy code like below and it worked:

    The odd thing is that, if I comment out the "this.enabled == true"
    test, get no log entry showing this.enabled as FALSE.
    Every log entry shows enabled = TRUE and immediately after that is the "allocate" error.
    I don't understand that unless, somehow, the log cannot execute on a disabled object,
    but the destroy command can and tries to and BOOM!

    If anyone knows the true reason, please let me know.
    Thanks.

    Code (csharp):
    1. Debug.Log ("Destroyed;  enabled? " + this.enabled);
    2.  
    3. if (this.enabled == true)
    4. {
    5.     Network.Destroy(networkView.viewID);
    6. }
     
  3. NaBUru38

    NaBUru38

    Joined:
    Jan 26, 2014
    Posts:
    12
    Hello, I've found the same issue. Apparently Network.Destroy() doesn't work if theobject is disabled.

    That if won't destroy the object in the peers. I think that the correct answer is to execute SetActive (true) before Destroy().
     
  4. NaBUru38

    NaBUru38

    Joined:
    Jan 26, 2014
    Posts:
    12
    I've just found that SetActive (true) must be also called on the client side, or the same error will appear. So after calling Network.RemoveRPCs(), there must be an RPC to all clients.