PhotonNetwork.Destroy() and PhotonNetwork.Instantiate() called twice on remote clients

Options

Here is the exact error message: ev destroy failed. could not find photonview with instantiationid.

The Destroy event is called when my player (local) dies to another player (remote), only local player instances on each machine are able to run their behaviour code (includind death/destroy behaviour) in my game. Notwithstanding, I am getting the error on the remote machines running the game, on the local one everything works as expected*.

I read a bunch of post related with my issue, thus I have ensured that:

  • I wrap my PhotonNetwork.Destroy() with photonView.IsMine check
  • The Destroy is sent towards an existing photonView with the supposed error instantiationid (I looked the values in the inspector before the destruction)
  • That code is only able to run locally because I disable/destroy the script on remote instances on Awake
  • Player prefabs (with their behaviours attached) are created by their own Client, then only destroyed by their local Client who created them with PhotonNetwork.Instantiate()

As a temporal workaround I have subtituted this PhotonNetwork.Destroy() (although it's the only one PhotonNetwork.Destroy() I have in my project yet) with this un-elegant solution:

[PunRPC]
private void LocalDestruction() => Destroy(gameobject);

However I'd like further info about what could be causing this error and how to deal with it, I did not send the whole PlayerManager Script, because I think it's unnecessarily big and mostly unrelated to this problem.

*In addition, after diying my players are supposed to respawn, which is done just by calling again the Instantiation code of the players from a GameManager. But to my surprise, this code is getting called twice on the remote clients, creating clones of my player. Although, it happens only when respawning, not when initially spawning.

Here is the instantiation code:

public void InstantiatePlayerOnLocal()
{
    var localPlayerManager = PhotonNetwork.Instantiate(playerPrefab.name, spawnPoint, Quaternion.identity).GetComponent<PlayerManager>();
}

My guess it's that all this code it's somehow getting called twice on remote clients for some reason as this will explain why this happens, but still I'll need how to solve it, because I don''t see when or how could this get called twice with all my ensurements.

Thanks