Send a message or RPC to single client?

The whole answer can be found below.

Please note: 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! And we offer you support through these channels:

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).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

Send a message or RPC to single client?

CameronO
2018-05-10 17:40:46

I haven't been able to find anything on this in the documentation, so if I've missed something I'd appreciate being pointed in the correct direction. Is it possible to send an RPC or raise an event to only a single client? This exists for MasterClient, which is great, but I don't see a way to send an event to a single client without spamming the room. Am I missing something obvious?

Comments

S_Oliver
2018-05-10 18:55:19

Hi, you can define Target Actor for event http://doc-api.photonengine.com/en/PUN/current/class_raise_event_options.html
https://doc.photonengine.com/en-us/pun/current/gameplay/rpcsandraiseevent

PhotonNetwork.RaiseEvent(eventCode, content, reliable, new RaiseEventOptions { TargetActors = new int[] { PhotonPlayer.ID } });

For RPC im not sure.

S_Oliver
2018-05-10 19:02:15

And the same is possible for RPC's

https://doc-api.photonengine.com/en/pun/current/class_photon_view.html#a6bc9726af14a8c7b8bdd7793c495a6e8

CameronO
2018-05-10 19:06:31

Sweet, thanks! That's very helpful.

lennart862
2018-05-11 01:24:48

@S_Oliver wrote:

Hi, you can define Target Actor for event http://doc-api.photonengine.com/en/PUN/current/class_raise_event_options.html
https://doc.photonengine.com/en-us/pun/current/gameplay/rpcsandraiseevent

PhotonNetwork.RaiseEvent(eventCode, content, reliable, new RaiseEventOptions { TargetActors = new int[] { PhotonPlayer.ID } });

For RPC im not sure.

Does everyone receive the message but only the defined actors execute it? And if not, it would be better for traffic to send only to these clients which should execute it instead to just send to "others" and leave it as default, right?

S_Oliver
2018-05-11 04:35:29

I dont know, hopefully @JohnTube or @Christian_Simon knows exactly, but I assume that the message/event only sends to the defined actor.

JohnTube
2018-05-11 09:01:30

if you send to target actors using their respective actor numbers than only those actors will receive the event / RPC.

llliao_104
2020-04-03 03:31:50

@JohnTube I want to send to the defined actors,could you tell me how to know the player's id?

JohnTube
2020-04-03 13:54:28

Hi @llliao_104,

It is not possible to send an RPC once to multiple "defined actors".
You can however send an RPC to a single actor using:

PhotonNetwork.RPC(string methodName, Player targetPlayer, params object[] parameters)  
PhotonNetwork.RpcSecure(string methodName, Player targetPlayer, bool encrypt, params object[] parameters)

So you may call this once per target actor.

Otherwise, use RaiseEvent for that and set the target actors using their respective actor numbers in raiseEventOptions.TargetActors.

Jimanji
2020-04-03 20:59:28

RPC and RaiseEvent are equal speed for send data ?

JohnTube
2020-04-03 21:29:39

Hi @Jimanji,

Yes almost identical as RPC uses RaiseEvent internally but may have a bit of overhead due to reflection and other stuff.

Back to top