Send a message or RPC to single client?
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).
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
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.
And the same is possible for RPC's
https://doc-api.photonengine.com/en/pun/current/class_photon_view.html#a6bc9726af14a8c7b8bdd7793c495a6e8
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/rpcsandraiseeventPhotonNetwork.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?
I dont know, hopefully @JohnTube or @Christian_Simon knows exactly, but I assume that the message/event only sends to the defined actor.
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?
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.
RPC and RaiseEvent are equal speed for send data ?
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