Enabling and Disabling objects over the network
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).
Enabling and Disabling objects over the network
Vallar
2018-07-08 11:21:28
Hi everyone,
First, sorry if this has been asked before but my search yielded nothing useful to me so I thought I'd ask.
Basically my issues is finding out how to enable and disable objects (both spawned and not spawned) over the network that don't have a PhotonView on them. Basically imagine this, I have a resource in the world that players gather. I need to disable them and re-enable them when I want (for performance reasons).
I tried using PunRPC to disable/enable and I got an error message that they don't serialize GameObjecs (I was passing the target GameObject to the RPC to disable it). I then tried to use RaiseEvent for the same thing and pass the GameObject in "content" but still, got the same error message.
So how do I disable an object I didn't spawn over the network and how do I disable an object I spawned over the network in PUN?
Thanks in advance.
Comments
Hi @Vallar,
Thanks for your reply @JohnTube
I am guessing that if I pass in a string name, I would have to do a GameObject.Find() to find the game object using that string, right? Unfortunately GameObject.Find() is a bad practice and should be avoided at all costs. Specially so if it is going to be run continuously. Unless of course there is another way to get an object by name I am not aware of in Unity that is far efficient than GameObject.Find() and its ilk.
Note that my use case pertains a resource that is being hunted by players on a regular basis.
In any case, I found another way, I just pooled the objects and shared their list's index around using events and used that to disable the correct object using RaiseEvent.
Back to top