Destroying Instantiated objects

Options
My instantiated player object instantiates a bullet. My script tells the bullet to destroy itself after a set amount of time. When the bullet destroys itself I get the following: "Received RPC "RPCDestroyBullet" for viewID 1015 but this PhotonView does not exist! Was remote PV. Owner called. By: #01 'Player45' Maybe GO was destroyed but RPC not cleaned up.
UnityEngine.Debug:LogWarning(Object)"

Here is my code...
void OnEnable()
    {
        StartCoroutine(DestroyBullet());
    }


    
    IEnumerator DestroyBullet()
    {
        yield return new WaitForSeconds(0.75f);
        DestroyMe();

    }

    
    void DestroyMe()
    {
        photonView.RPC("RPCDestroyBullet", RpcTarget.AllViaServer);
    }

    [PunRPC]
    void RPCDestroyBullet()
    {
        
        Destroy(gameObject);
    }

Comments

  • ArlenB
    Options
    What am I missing here?
  • ArlenB
    Options
    I had tried PhotonNetwork.Destroy(gameObject); as well but had similar issues. I just tried it like this and it seems to be working...
    IEnumerator DestroyBullet()
        {
            yield return new WaitForSeconds(0.75f);
            if (photonView.IsMine)
            {
                PhotonNetwork.Destroy(gameObject);
            }
    
        }
    

    I was missing the photonView.IsMine check before.