Change scene object tag over network

Options
Hello,
I have some sceneObjects that exist in the hierarchy, and a script attached to them which makes them activate one of their 3 childs depending on the tag, but I only see the change locally.

I think that I should be using RaiseEevents or RPCs, but I still can't figure out how to use them even after 2 months using PUN and going through all the video tutorials and documentations.

I wrote about my problem previously here with more details : https://stackoverflow.com/questions/53729703/change-seneobject-tag-over-network-photon-unity

If anyone can please point me how can I solve that it will be pretty useful.

If RPC are whar I need in this situation, can anyone please give me an example of how to use them to send more complex data like Strings, GameObjects...?

Thank you ^^

Comments

  • Hi @Mehdi22,

    have you already taken a look at our documentation page about RPCs and RaiseEvent?

    Since you have Scene Objects you can use RPCs in your case. To call an RPC, you have to get a reference to the object's attached PhotonView component first. You can do this in the Awake or the Start function by using pView = GetComponent<PhotonView>();. If you have this reference, you can call the RPC function of that component. As an example: pView.RPC("TheNameOfTheFunction", RpcTarget.AllViaServer);. This is a simple call which will call a function named "TheNameOfTheFunction" on all clients (RpcTarget.AllViaServer) in the room. In your case, you want to add the tag of the game object to that RPC call. It should look similar to this one: pView.RPC("TheNameOfTheFunction", RpcTarget.AllViaServer, "MyTag"));. When using the RPC function, you can simply add parameters to it. If you allow clients, to join the game later, you would have to think about replacing RpcTarget.AllViaServer with RpcTarget.AllBufferedViaServer. The difference is, that in the second case the RPC call gets buffered on the server and a client, who joins the game after this RPC has been called, will receive it on joining the room and process it, too. This might be important for keeping the game synchronized. You can find further information about this topic on the above mentioned documentation page, too.

    Now you have to implement a function called "TheNameOfTheFunction", add all the parameters you need and mark it with the [PunRPC] attribute. For the example above, it looks like this:
    [PunRPC]
    public void TheNameOfTheFunction(string myTag) { }
    In this function, you can now update the Tag of the game object and (de-)activate its child objects depending on the Tag. Please make sure, that only one client (for example the MasterClient) uses this function. Please note, that the RPC is only executed on the same object it has been called on. For example: if you use the RPC function on Object A, the [PunRPC] marked function gets called on Object A only, not on Object B or other objects.
  • Mehdi22
    Options
    @Christian_Simon thank you very much :smiley: now I have a clearer view.

    If I understand well, the functions parametres should be added after the RPC's targets right?
    else, everything was so clear thank you very much :blush:
  • If I understand well, the functions parametres should be added after the RPC's targets right?


    Yes, exactly.