How do I destroy NPC while not Master.

Hello

I have a test scene with two characters and NPC enemies. When an NPC is reduced to zero hp a death animation is played and at the end of that animation this method is triggered

private void DestroySelf()

  {

    PhotonNetwork.Destroy(gameObject);

  }

This works just fine when playing as the master client but loops the animation when not master client. I understand that you must be master to use PhotonNetwork.Destroy.

So my question is how can I destroy an npc while not master?

Best Answer

  • Tobias
    Tobias admin
    Answer ✓

    You should be communicating hits already. So when an NPC gets hit, everyone knows.

    The controller of said NPC (the one sending updates, likely the Master Client) should calculate that HPs became 0, play the animation and Destroy the object.

Answers

  • Tobias
    Tobias admin
    Answer ✓

    You should be communicating hits already. So when an NPC gets hit, everyone knows.

    The controller of said NPC (the one sending updates, likely the Master Client) should calculate that HPs became 0, play the animation and Destroy the object.

  • Thanks for the response.

    I used an RPC to handle the damage across all clients which in turn triggered the death animation and the destroy self method. I also changed the destroy self method:

    if (PhotonNetwork.IsMasterClient)

          PhotonNetwork.Destroy(gameObject);


    This way only the master client is doing the destroying for all clients.

  • Thanks for the update.