Finding an item by its photonview id..
The whole answer can be found below.
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).
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
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)
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?
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...
Back to top@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?