Failed to 'network-remove' GameObject because it is missing a valid InstantiationId on view:

Options
Failed to 'network-remove' GameObject because it is missing a valid InstantiationId on view: View 4 on AmmoPack (scene). Not Destroying GameObject or PhotonViews!


HI!

I am receiving the above error in one of my projects using photon.

Upon a trigger, I am attempting to destroy a game object using the code below over the photon network.

private void OnTriggerEnter(Collider other)
    {
        //check if this client/player is the host.
        if(!PhotonNetwork.IsMasterClient)
            return;

        if (other.CompareTag("Player"))
        {
            PlayerController player = GameManager.instance.GetPlayer(other.gameObject);
            
            if(type == PickupType.Health)
                player.photonView.RPC("Heal", player.photonPlayer, value);
            else if(type == PickupType.Ammo)
                player.photonView.RPC("GiveAmmo", player.photonPlayer, value);
            
            PhotonNetwork.Destroy(gameObject);
        }
    }

The problem is with PhotonNetwork.Destroy(gameObject). All code above seems to work fine.

When I go to pickup the object, once PhotonNetwork.Destroy(gameObject) is called, it crashes the application and gives the error.

The exact location of the error is in the PhotonNetworkPart.cs file, in the code below.

PhotonView viewZero = views[0];
            int creatorId = viewZero.CreatorActorNr;            // creatorId of obj is needed to delete EvInstantiate (only if it's from that user)
            int instantiationId = viewZero.InstantiationId;     // actual, live InstantiationIds start with 1 and go up
            
            // Don't remove GOs that are owned by others (unless this is the master and the remote player left)
            if (!localOnly)
            {
                //Debug.LogWarning("Destroy " + instantiationId + " creator " + creatorId, go);
                if (!viewZero.IsMine)
                {
                    Debug.LogError("Failed to 'network-remove' GameObject. Client is neither owner nor MasterClient taking over for owner who left: " + viewZero);
                    return;
                }
                Debug.Log("Test");

                // Don't remove the Instantiation from the server, if it doesn't have a proper ID
                if (instantiationId < 1)
                {
                    Debug.LogError("Failed to 'network-remove' GameObject because it is missing a valid InstantiationId on view: " + viewZero + ". Not Destroying GameObject or PhotonViews!");
                    return;
                }
            }

The reason it gives an error is because the InstantiationId is 0.

If I change the following line:

int instantiationId = viewZero.InstantiationId;

to:

int instantiationId = viewZero.ViewID;

It seems to work fine. Though I am not sure if this is the right way to fix it as I am not sure how important the instantiationId is.

I have seen this work fine in other projects before, where the instantiationId is just the exact same as the ViewID.

Is there a better solution to this issue, or perhaps is it a bug?

I am running PunVersion 2.15.

Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @OrANgE_x_Eddie,

    Thank you for choosing Photon!

    I assume the networked scene object is not instantiated at runtime, it's there in the scene at compile time (when the scene is loaded), right?

    The same issue was reported here before.

    You could use an RPC instead of the normal PhotonNetwork.Destroy in this case.