Enabling and Disabling objects over the network

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,

    I tried using PunRPC to disable/enable
    Yes that is the way to go.
    I got an error message that they don't serialize GameObjecs (I was passing the target GameObject to the RPC to disable it)
    You should exchange some kind of unique reference or ID or pointer to the GameObject. Like its name (string) if it's the same on all clients. etc. Read about Photon Serialization and supported or custom types here.
    I then tried to use RaiseEvent for the same thing
    You should know that PunRPC is RaiseEvent under the hood.
  • Thanks for your reply @JohnTube

    You should exchange some kind of unique reference or ID or pointer to the GameObject. Like its name (string) if it's the same on all clients. etc.


    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.
Sign In or Register to comment.