Ev Destroy Failed. Could not find PhotonView with instantiationId 1315. Sent by actorNr: 1

I am very angry!🤬

Why? Because using your product made my game development hell!

Before starting development, I studied the documentation in which a lot of things were not clear to me. The only thing I understood is to use PhotonNetwork.Instantiate to spawn an object, to destroy PhotonNetwork.Destroy(gameObject).

OK. According to this principle, I wrote the logic of the game. But as a result, I constantly get errors because other clients cannot destroy an object that has already been destroyed! I started looking for information on how to fix this error and was shocked because this problem (error) has existed since 2015 and to this day this problem has not been fixed!😨

Tips to fix this error is to use

if (photonView.IsMine) PhotonNetwork.Destroy(gameObject);

BUT! I still get this error.

OK. I started experimenting and found a solution by typing

if (photonView)
            {
                //if (photonView.IsMine) PhotonNetwork.Destroy(gameObject);
                if (photonView.IsMine) photonView.RPC("DelBullet", RpcTarget.MasterClient);
                //else photonView.RPC("DelBullet", RpcTarget.Others);
            }
[PunRPC]
    void DelBullet()
    {
        PhotonNetwork.Destroy(gameObject);
    }

And this solution worked!🤩

After that, I made changes to all scripts that destroy objects and launched the game.

Do you now think that everything is ok? NO! I got this error again. What the hell..🙁

I'm tired of looking for solutions.🙁

Photon developers.. I have one question: No offense, but are you professionals or losers? Why haven't you fixed this problem in 7 years?🤷‍♂️

I spent two months developing my game using Photon and ended up with a half working game because only one person can play it.

Developing a photon is just a mockery on your part ...

Comments

  • My experiments:

    PhotonView photonView;


      private void Start()

      {

        photonView = GetComponent<PhotonView>();

      }


      private void OnTriggerEnter2D(Collider2D coll)

      {

        if (coll.CompareTag("Bullet"))

        {

          if (gameObject.CompareTag("bwall"))

          {

            Del();

          }

        }

      }


      void Del()

      {

        if (photonView != null)

        {

          //if (photonView.IsMine) PhotonNetwork.Destroy(gameObject);

          //if (photonView.IsMine) photonView.RPC("DelWall", RpcTarget.AllViaServer);

          //else photonView.RPC("DelWall", RpcTarget.MasterClient);

          //if (photonView.IsMine) photonView.RPC("DelWall", RpcTarget.MasterClient);

          //if (photonView.Controller.IsMasterClient) photonView.RPC("DelWall", RpcTarget.AllViaServer);

          //else photonView.RPC("DelWall", RpcTarget.MasterClient);

          //if (photonView.Controller.IsMasterClient) PhotonNetwork.Destroy(gameObject);

          //else photonView.RPC("DelWall", RpcTarget.MasterClient);


          if (photonView.Controller.IsMasterClient) PhotonNetwork.Destroy(gameObject);

          else if (photonView.IsMine) PhotonNetwork.Destroy(gameObject);

          else photonView.RPC("DelWall", RpcTarget.MasterClient);

        }

      }


      [PunRPC]

      void DelWall()

      {

        PhotonNetwork.Destroy(gameObject);

        /*gameObject.SetActive(false);

        Destroy(gameObject, 2f);*/

      }


    as a result only errors


  • The screenshot is old but the errors are identical

  • You use PhotonNetwork.Instantiate to create networked objects. The client which creates the object, should also PhotonNetwork.Destroy it. If you transfer ownership or if the creator of an object is gone, the Controller client should PhotonNetwork.Destroy it.

    You use IsMine to check if the client controls the object (good) but then send an RPC to the Master Client to call PhotonNetwork.Destroy. However, you want to send the RPC to the Controller of the object. Again: In most cases, the Master Client only controls an object, if the creator left the room already.

    So: Send this RPC to the Controller of the object.

    And: Make sure only one player decides that the object needs to get destroyed. If all players will each tell the Controller to destroy the object, then the first such RPC will destroy it and the other RPCs will no longer have a target to call the method on!


    In best case, the Controller of an object should detect if it needs to get destroyed. Let's say a player shoots and hits some character. Send an RPC to everyone that there was a shot that hit the target object. Everyone gets this and runs logic in the RPC method. Each player also checks IsMine and only when that's true, that client calls PhotonNetwork.Destroy for the object.

    No conflicts.

  • Tobias, your answer confused me even more.😵

    I provide you with all the information that will give you an understanding of how the logic of my game works.

    Screenshots:


    Scripts:

    this script is responsible for the movement and destruction of the bullet when it hits the triggers of objects

    using Photon.Pun;
    
    
    using System.Collections;
    using System.Collections.Generic;
    
    
    using UnityEngine;
    
    
    public class Bullet : MonoBehaviour
    {
        public bool IsPlayer = false;
        public bool IsHeavy;
        public int tanklvl;
    
    
        float standardSpeed = 5f;
    
    
        PhotonView photonView;
    
    
        private void Start()
        {
            photonView = GetComponent<PhotonView>();
        }
    
    
        private void FixedUpdate()
        {
            SetSpeed();
        }
    
    
        private void OnTriggerEnter2D(Collider2D coll)
        {
            if (coll.CompareTag("Player") ||
                coll.CompareTag("Enemy") ||
                coll.CompareTag("Bullet") ||
                coll.CompareTag("GameWall") ||
                coll.CompareTag("swall") ||
                coll.CompareTag("bwall"))
            {
                if (photonView)
                {
                    //if (photonView.IsMine) PhotonNetwork.Destroy(gameObject);
                    if (photonView.IsMine) photonView.RPC("DelBullet", RpcTarget.MasterClient);
                    //else photonView.RPC("DelBullet", RpcTarget.Others);
                }
            }
        }
    
    
        public void SetSpeed()
        {
            transform.Translate(Vector2.up * standardSpeed * SetSpeedForLvl(tanklvl) * Time.fixedDeltaTime);
        }
    
    
        float SetSpeedForLvl(int tanklvl)
        {
            var speed = 0.0f;
            switch (tanklvl)
            {
                case 1:
                    speed = 1f;
                    break;
                case 2:
                    speed = 1.5f;
                    break;
                case 3:
                    speed = 1.7f;
                    break;
                case 4:
                    speed = 1.3f;
                    break;
            }
            return speed;
        }
    
    
        [PunRPC]
        void DelBullet()
        {
            PhotonNetwork.Destroy(gameObject);
            //Destroy(gameObject, 2f);
        }
    }
    


    this script is responsible for destroying the walls. The wall should be destroyed if it is hit by a bullet.

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using Photon.Pun;
    
    
    public class Walls : MonoBehaviour
    {
        PhotonView photonView;
    
    
        private void Start()
        {
            photonView = GetComponent<PhotonView>();
        }
    
    
        private void OnTriggerEnter2D(Collider2D coll)
        {
            if (coll.CompareTag("Bullet"))
            {
                var heavy = coll.gameObject.GetComponent<Bullet>().IsHeavy;
                if (gameObject.CompareTag("swall") && heavy)
                {
                    Del();
                }
                else if (gameObject.CompareTag("bwall"))
                {
                    Del();
                }
            }
        }
    
    
        void Del()
        {
            //if (photonView.IsMine) PhotonNetwork.Destroy(gameObject);
            //if (photonView.IsMine) photonView.RPC("DelWall", RpcTarget.AllViaServer);
            //else photonView.RPC("DelWall", RpcTarget.MasterClient);
            if (photonView.IsMine) photonView.RPC("DelWall", RpcTarget.MasterClient);
        }
    
    
        [PunRPC]
        void DelWall()
        {
            PhotonNetwork.Destroy(gameObject);
            /*gameObject.SetActive(false);
            Destroy(gameObject, 2f);*/
        }
    }
    
    So, 
    So, 
    So, 
    

    So, I hope that the information I provided helped you understand what and how it works.

    Now the question is: how is it that the bullets fired by the enemy belong to different owners, controllers?

    I don't know how a Photon works from the inside. In this regard, I don't understand how then I can determine who the owner of the object is and how to properly destroy the object, or how and to whom to inform to destroy the object.

    Therefore, the best answer from you for me will be to make changes to my scripts.

  • If you transfer ownership or if the creator of an object is gone, the Controller client should PhotonNetwork.Destroy it.

    In my game there is no transfer of ownership to another client. If the player who created the room and started the game exits, then the game is over.

  • evgeny_berezhnoy_92
    edited November 14

    Dude, why are you destroying the gameobject itself? PhotonNetwork.Destroy is overloaded with PhotonView signature. Destroy the PhotonView - I believe it could solve your dilemma.

  • Dude, this doesn't work.

  • Could you share the reference on your repo so I could have a look? Only in case this is not commercial, of course.

  • To figure out why the ownership is what it is, you would have to show instantiation code. The covered code is about destroying stuff.

    When there is a collision, you check if the script runs on the controller of the Wall. Then you send an RPC to the Master Client but .. that's not needed. The controller of the Wall can PN.Destroy() said wall. Right away. No need to involve the Master Client.

    The RPC is an indirection here, which is not needed.

    When you PN.Destroy the object, it is gone immediately, locally. If now someone else is calling RPCs on this, then those will fail and log the warning. This may happen.

    Similarly, the Bullet script is running on the Bullet objects and if you check that the controller (IsMine) calls an RPC on it, then skip the RPC and PN.Destroy the Bullet.

  • To figure out why the ownership is what it is, you would have to show instantiation code. The covered code is about destroying stuff.

    Quote from email

    We simply won't work on your code. That is called consulting and we don't do it, because we are busy already.

    after reading, I removed all the code that could possibly help in solving this problem



    Your reaction to my info was just "what" instead of "I gave it a try and this is what I can't get to work".

     //if (photonView.IsMine) PhotonNetwork.Destroy(gameObject);
    
          //if (photonView.IsMine) photonView.RPC("DelWall", RpcTarget.AllViaServer);
    
          //else photonView.RPC("DelWall", RpcTarget.MasterClient);
    
          //if (photonView.IsMine) photonView.RPC("DelWall", RpcTarget.MasterClient);
    
          //if (photonView.Controller.IsMasterClient) photonView.RPC("DelWall", RpcTarget.AllViaServer);
    
          //else photonView.RPC("DelWall", RpcTarget.MasterClient);
    
          //if (photonView.Controller.IsMasterClient) PhotonNetwork.Destroy(gameObject);
    
          //else photonView.RPC("DelWall", RpcTarget.MasterClient);
    
    
    
    
          if (photonView.Controller.IsMasterClient) PhotonNetwork.Destroy(gameObject);
    
          else if (photonView.IsMine) PhotonNetwork.Destroy(gameObject);
    
          else photonView.RPC("DelWall", RpcTarget.MasterClient);
    

    did it just write itself?



    And as last point in this mail: Just because you find the issue happening in some cases over the yeas, does not mean it is ours to solve.

    Bad analogy: If someone puts diesel into their gasoline car, it is not the manufacturers problem.

    The solution to these problems is to now use PUN in the wrong way.

    In short, if you have a PUN problem, that's your problem.

    Ок.

    I'm going to solve the problem myself. I will remove the photon and forget this nightmare

  • did it just write itself?

    That code was posted before I replied initially. I know you tried a lot but I didn't see changes done once you got feedback. I can not guess the progress.

    In short, if you have a PUN problem, that's your problem.

    To a degree, yes. I am sorry you see it this way. The point was: We can provide a manual and help but there is no way we can prevent all error cases and incorrect use. So we try to explain how things work. This is apparently where I failed.

    I am sorry you lost time due to this all. Hope you find what you seek.