Removing PhotonViews via Code

Options
Hello!

I have been having an issue where I need to remove a PhotonView from a GameObject. I can't just use Destroy(PhotonView) because it needs to be with any other PhotonViews syncing with it (so I guess any other PhotonViews with the same ViewID).

Is there any way to to do this?
Thanks!

Edit:
Fixed gibberish (I said gameObject.removeComponent instead of Destroy(), when in fact removeComponent doesn't exist! *Self-Facepalm*)

Best Answer

  • Tobias
    Tobias admin
    Answer ✓
    Options
    Use PhotonNetwork.Destroy(PhotonView targetView), if you created the object with PhotonNetwork.Instantiate().
    That should turn the Destroy-call into a networked one.

Answers

  • Tobias
    Tobias admin
    Answer ✓
    Options
    Use PhotonNetwork.Destroy(PhotonView targetView), if you created the object with PhotonNetwork.Instantiate().
    That should turn the Destroy-call into a networked one.
  • Stekon
    Options
    Tobias said:

    Use PhotonNetwork.Destroy(PhotonView targetView), if you created the object with PhotonNetwork.Instantiate().
    That should turn the Destroy-call into a networked one.

    This is what I was looking for. Thanks!
  • Stekon
    Stekon
    edited April 2019
    Options
    Tobias said:

    Use PhotonNetwork.Destroy(PhotonView targetView), if you created the object with PhotonNetwork.Instantiate().
    That should turn the Destroy-call into a networked one.

    Ok so I wasn't actually able to implement this at the time, but it looked like it was what I needed. But this destroys the GameObject with the PhotonView, where I need to just destroy the PhotonView on the GameObject, without destroying the GameObject itself. Sorry about this. Any ideas?
  • devonlively
    Options

    I'm looking for this solution as well, if someone has the right way to do this id appreciate it.

  • Tobias
    Options

    You could look into Manual Instantiation, described here. With it, you can add and remove PhotonViews from objects of your liking.

    We can't really provide samples for that, sorry.