Can't get rid of error "Ev Destroy Failed"

Options
D3Duck
D3Duck
Full error message:
Ev Destroy Failed. Could not find PhotonView with instantiationId 2007. Sent by actorNr: 2

My scene is very simple. I have one enemy that spawns after the player has entered (his ID in this case was 2007). When I kill it with the master client there is no error. When I kill it with the second client (actor 2) I get this error above.

The setup of the code is that an ability is fired, which contains all the data of the ability such as damage. When the ability hits the health of the enemy is taken away like so:

    //Script attached to the enemy GameObject

    [PunRPC]
    public void MinusHealth(int amount)
    {
        currentHealth -= amount;

        if (currentHealth < 0)
            currentHealth = 0;

        healthSlider.value = currentHealth;

        if (currentHealth == 0 && !isDead)
        {
            Death();
        }
    }

    void Death()
    {
        isDead = true;
        NPCAI.enabled = false;
        agent.enabled = false;

        //TODO play death animation

        //TODO only add exp to correct players
        GameController.GC.baseCharacter.AddExp(NPCAI.EnemyLevel * 21);
        MCC.UpdateExperienceUI();

        Debug.Log("Instantiation ID is " + GetComponent<PhotonView>().instantiationId + ".");

        //Everyone keeps track by themselves of the health, but only the master client can kill it
        if(PhotonNetwork.isMasterClient)
            photonView.RPC("DestroyThisGO", PhotonTargets.All, null);
    }

    [PunRPC]
    void DestroyThisGO()
    {
        //Destroy the GO, this can only be done by the person who 'owns it'.
        //PhotonNetwork.Destroy() is called by this client and will destroy on all clients
        if (GetComponent<PhotonView>().instantiationId == 0)
        {
            Debug.Log("1");
            Destroy(gameObject);
        }
        else
        {
            Debug.Log("2");
            if (this.photonView.isMine)
            {
                Debug.Log("3");
                PhotonNetwork.Destroy(photonView);
            }
        }
    }
As far as I have been able to test the error is at the DestroyThisGO function. It seems to me like a client is trying to call the PhotonNetwork.Destroy even though this was already done. I do not see why this would happen since I have it coedd that only the master client calls the RPC, so it only gets done once. And then the only client calling the destroy function should in this case also be the master client since he is the one who owns the enemy.

Comments

  • D3Duck
    Options
    As additional note. I get the error but everything works perfectly, the enemy GameObject is destroyed and that's it. So it really seems to me it is just a matter of calling the destroy function twice somehow.
  • vadim
    Options
    Why do you need Destroy(gameObject)?
    All objects created with PhotonNetwork.Instantiate should be destroyed with PhotonNetwork.Destroy.
    Just call it on master w/o sending "DestroyThisGO" RPC.
  • D3Duck
    Options
    I removed that piece of the code now, but still same problem. As far as I understood the client that created also needs to destroy. That's why I used the RPC to send to all and then the one that had photonView.IsMine would call the PhotonNetwork.Destroy()
  • vadim
    Options
    Make sure that you call PhotonNetwork.Destroy() once and do this on object owner. I think it's quite simple to trace.
    I don't know how MinusHealth is called. But it's better to have this call only on owner as well. The owner can update others with new health value or remove object.