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! Your search result can be found below. Plus, we offer support via these channels:

Try Our

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.

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.

RPC call on another Gameobject

2020-12-03 18:56:39


unfortunately I am still struggling with the RPC calls.
In my game I have one Gameobject that should serve as a "button" (the type is not an UI button, its a 3D-Object with a Mesh) to (de-)activate another Gameobject. So if a click on the first Gameobject is recognized, the second one should be activated or deactivated for all clients.

I wanted to realize this via RPC calls. The script is attached to the "button"-Mesh, the GameObject and the PhotonView belong to the second GO which I want to (de-)activate.

If I test it in unity the console tells me:
"Exception: Write failed. Custom type not found: UnityEngine.GameObject"
but also:
"Sending RPC "SetThisInactive" to target: All or player:."

So is it not possible to synchronize the status of a Gameobject via RPC? How can I synchronize the (De-)Activation of an GameObject via PUN?


2020-12-03 19:26:14

You cannot send GameObject, PhotonViews, or complex types via the Photon Network. You can only send simple variable types such as strings, ints, and floats. Thus, your solution would be to use those instead. So locally you send the view ID of the game object you want activated/deactivated, and then on the remote side, you find that ID. If the sending and receiving GO is the same, this is unnecessary.

PhotonView.Find(ID).gameObject.SetActive(false); //WHEN IT IS NOT SAME OBJECT

But in your case, you can just call the RPC without having any parameters.

You're welcome B)

2020-12-05 23:49:22

Ah, nice, that makes sense! Thank you very much!

Unfortunately I still get an Error (No matter if I implement the functions with or without the PhotonView ID as a parameter):

"RPC method 'SetThisInactive(Int32)' not found on object with PhotonView 2. Implement as non-static. Apply [PunRPC]."

I mean, the function is not on the object with ID 2, the script is attached to the "Button" object. And [PunRPC] is applied...
So, I have to apply the functions marked with [PunRPC] on another script which is attached to the Object I want to deactivate/activate and call them on the script which is attached to the "Button" Object then?

2020-12-10 20:06:42

Now it works. As I already guessed, I had to create a second script and attach it to the object which should be (de)activated.
So the script where the RPC call takes place is attached to the Gameobject which serves as a button and the script where the [PunRPC] functions are defined is attached to the Gameobject which should be (de)activated.

Back to top