[SOLVED] Destroy Problem

Hello, i use Unity 4 and PUN 1.17.

In my game the player can shoot bullets. After X second i destroy this bullet. Players and bullet have a Photon View.

Here is the code i use to Instantiate :
var newBomb = PhotonNetwork.Instantiate("Balle", transform.position, spawnPoint.transform.rotation,0);

Here is the code i use to destroy the bullets:
yield WaitForSeconds (0.25);
PhotonNetwork.Destroy (this.gameObject);

The problem is with the client. The master work correctly, but when the client shoot bullets and destroy came i receive this error message :
"Cannot call Destroy(GameObject go); on the gameobject "Bullet(Clone)" as we don't control it"



  • Tobias
    That's a problem with ownership of bullets and the timing.
    On object with a PhotonView is owned/controlled by the player who instantiated it. Only the controlling player or master client can destroy objects, so bullets will have to be destroyed by the owner in your case.

    Talking about bullets with PhotonViews:
    Using a PhotonView per bullet and PhotonNetwork.Instantiate for each is a lot of network overhead while you don't gain a lot. The objects are short lived and plenty. For those, better use a RPC that sends "at time x i was here and shot in that direction". The RPC won't be buffered and thus doesn't need another clean call when the bullet is destroyed.
    Whoever calculates hits can also send the RPC "i hit y for z damage" or so.
  • Hello Tobias. thanks for your reply.
    I understand the concept but not in practice.
    Because in my game, each player can shoot bullet and then destroy their own bullet, but that's not work! The object bullet have their own PhotonView, but i received always the message "Cannot call Destroy(GameObject go); on the gameobject "Bullet(Clone)" as we don't control it", but each player have the control to destroy their own bullet ??
    What i'm doing wrong?

    Talking about bullets with PhotonViews:
    Yes i have change my way about that, but i really need to to destroy other object in the scene.
  • Tobias
    In your code, every player creates it's own bullets. As you use PhotonNetwork.Instantiate(), they get created on the other player's clients as well.
    You however try to destroy all bullets only on the master (checking if(PhotonNetwork.isMasterClient)). This master is not controlling bullets of other players unless they left the room.
    Per bullet, check the property PhotonView.isMine. If the destroy script is a Photon.Monobehaviour and on the bullet GameObject, you check this.photonView.isMine.
  • Thanks, work's well now!