PhotonNetwork.Destroy object that was manually instantiated

Options
In a previous version of PUN i didn't have a problem destroying objects that were manually instantiated via the following code:

[code2=csharp]Transform objectInstance = (GameObject.Instantiate(objectPrefab, playerTrans.position, playerTrans.rotation) as GameObject).transform;
objectInstance.transform.parent = playerTrans;
PhotonView[] nViews = objectInstance.GetComponentsInChildren<PhotonView>();
nViews[0].viewID = viewID;
if(onSpawned != null){
onSpawned(objectInstance.gameObject);
}[/code2]

But in the latest version 1.22.3, when calling PhotonNetwork.Destroy(_photonView); on such an object I get the following error:

Failed to 'network-remove' GameObject because it is missing a valid InstantiationId on view: View (0)1003 on Player Bumper(Clone) . Not Destroying GameObject or PhotonViews!

I don't see any mention of having to manually set an InstantiationId in the documentation. But should I? And if so how do i set it? Presumably the id needs to be unique?

Cheers.
Matt

Comments

  • Tobias
    Options
    No, you don't have to set a instantiation ID of course but if you don't use PhotonNetwork.Instantiate, the objects simply won't have one. This is our internal marker for "not instantiated in the network".
    Simply use GameObject.Destroy(), matching GameObject.Instantiate().
  • Ok I see. I'll have to have a manual destroy rpc to go along with my manual instantiate rpc. Makes sense now. Thanks.
  • Tobias
    Options
    I think I can make the error message more clear. In other places it also turned out to immediately give hints for fixed. This one is particularly unclear.
    Sorry :)
  • skeptika
    Options
    Sorry to resurrect a thread, but I'm having the same issue, in a slightly different context.

    I'm unable to delete scene owned objects (objects already placed in the scene with a photonview). If I understand the above, I should be manually deleting these objects via RPC, but I'm unclear how you'd accomplish manually destroying. As I understand it, photon won't serialize the gameobject you want to destroy, so how would you manually destroy this via RPC (how can I inform a client to destroy THIS object if I can't send it)?

    Does the question make sense? If it doesn't I'll try again, but fundamentally I can't figure out how to destroy (across the network) an object that comes with the scene. PhotonNetwork.Destroy won't work, and Destroy itself will only work on the computer calling it, not across the network.
  • Tobias
    Options
    You don't have to send "this GameObject". Instead, just call the RPC on that GameObject and only the named method on that GO will execute.
    However, this means you start calling RPCs on GOs that might get deleted anytime. Even shortly before an RPC is executed. This will lead to error messages, as the RPC can't be executed on the target it has. It's not really a bug, if the GO you want to delete is already deleted but it can be confusing.

    Instead you can also send an RPC on some "static" GameObject. That GameObject stays in game all the time, so RPCs will "find it" and successfully execute.
    In the RPC you can send the PhotonView's viewID, instead of the GO. Through the viewID, you can find any PhotonView and in turn the GO it's attached to.