Local GameObject instantiation (duplication) of an object with a PhotonView destroys original.

Options
Hey all,

I'm working on a multiplayer Vive game, and one of the features is object selection - when you move the controller cursor over a selectable object, it uses Instantiate(objectTargeted), then makes the copy a pale, transparent blue. When I added a PhotonView to catch RPCs for having moved the object, though, that Instantiate() call causes the following error:

"PhotonView ID duplicate found: 17. New: View (0)17 on OriginalObject(Clone) (scene) old: View (0)17 on OriginalObject (scene). Maybe one wasn't destroyed on scene load?! Check for 'DontDestroyOnLoad'. Destroying old entry, adding new."

And it deletes the OriginalObject, leaving me with only the transparent clone. Here's what I've tried so far:
(1) I tried to create an empty GameObject and copy over mesh data instead, but the model I imported was dirty, it doesn't have a MeshFilter and I'm unable to extract mesh information.
(2) I tried to destroy the PhotonView() on the copy as soon as it was created - apparently not fast enough, because it didn't work.

The only other way I can think of to do it would be to have each imported object be childed to an empty GameObject that carries the PhotonView, which would apply the RPCs to its children, but this would be far from ideal as I'm dealing with large imported scenes with dozens of objects, and I would have to individually add all of them.

Any help/elucidation would be much appreciated.

Comments

  • kittyLLLL
    Options
    Change the photonview ID of the new object so that it doesn't delete the previous object with the same ID. I think you can use AllocateID () but I'm not sure.

    Also are you using PhotonNetwork.Instantate or just Instantiate???
  • MarshallN
    MarshallN
    edited February 2017
    Options
    Just Instantiate(), I'm only trying to make a local copy. I ended up fixing the problem by going into PhotonEngine's "NetworkingPeer" script and changing the behaviour for when it detects a new object with a ViewID that's already been allocated. It only ended up being a few lines changed, but now instead of deleting the object that had the ViewID first, I just delete the PhotonView of the new one so there's no conflict, which results in the behaviour I was looking for.

    Specifically, this was the main change, in the function "public void RegisterPhotonView(PhotonView netView)". Where it says "this.RemoveInstantiatedGO(listedView.gameObject, true);", I replaced that line with "GameObject.Destroy(netView);". There were a couple of other lines to change to make it stop throwing errors out at me, but that was the change I was looking for.

    I didn't try using AllocateID(), but I don't think it would have worked - the old object was being deleted as soon as I called Instantiate(), before the subsequent line (where I was deleting the PhotonView of the copy) was executed.
  • bdar
    Options
    What if you simply created a new PhotonView component on the run?