Finding an item by its photonview id..

The whole answer can be found below.

Please note: The Photon forum is closed permanently. After many dedicated years of service we have made the decision to retire our forum and switch to read-only: we've saved the best to last! And we offer you support through these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

Finding an item by its photonview id..

benk0913
2013-06-22 21:29:34

Well, Ive been trying to code that when the player picks an item, he sends the master client a request to destroy its gameObject from the scene. Thats because the client is not its owner and I could do that just with photonnetwork.destroy..

Now, Ive made a method which picks the items photonviews id and sends it by an rpc to the master client. The master client recieves the photonview id and from there... Im stuck, I can't figure out how to locate the gameObject by its photonview id.

How do I do that? Is there a better way to do so?

Many thanks for anyone who helps. :)

Comments

Chubysnow
2013-06-23 14:29:24

To find a photon view by the id you can use PhotonView.Find(x); (x is the id, an integer). That returns the value of the photon view. To find the game object just add a .gameObject after (x)

benk0913
2013-06-24 14:44:25

Many thanks, I used that :)

hopetolive
2020-02-09 12:47:37

Thanks so much :smiley: Do you know that is this method optimal? I mean using "GameObject.Find()" is expansive operation for games. Is "PhotonView.Find(x)" also not good method to use? Do they work in similar ways?

bdar
2020-09-28 14:57:09

IMHO I think it might be (way) more optimal than GameObject.Find() because Photon actually pools everything that got instanced via PhotonNetwork.Instantiate(). But someone from Photon would give a more proper answer to that...

@hopetolive wrote: »

Thanks so much :smiley: Do you know that is this method optimal? I mean using "GameObject.Find()" is expansive operation for games. Is "PhotonView.Find(x)" also not good method to use? Do they work in similar ways?

Back to top