How to: Send an event from server to a specific client?
Options
chr
✭
in Photon Bolt
It seems standard events will be sent to all clients. Which could work, but would be wasteful.
I imagine I'll need the BoltConnection of the client.
I imagine I'll need the BoltConnection of the client.
0
Comments
-
I think I've answered my own question. It's possible to send a bolt event to a specific client (from the server). When you Create the event you can pass a BoltConnection.0
-
Yup. Off the top of my head.
entity.controller is bolt connection of client (only on server this works)
var your_event = YourEvent.Create(entity.controller);
your_event.Send();
also, I am certain that if the entity.controller is null (server player) it will send the event to the server player.
Off-topic:
But if you want a client to send an event to another client.
Client A sends event to server with Client B entity.
Server will route/send event to Client B with entity (from Client A)0 -
You could use the same event if you want.
You pretty much use the server as a proxy since clients have no direct access to each other.
Client A -> Server -> Client B1 -
Okay But how should Client B recieve the event
0 -
Hello,
Please, take a look on our dedicated page about Bolt Events: https://doc.photonengine.com/en-us/bolt/current/gameplay/events
--
Ramon Melo
Photon Bolt Team0 -
I read docs in the link above + watched tutorial. There is no example. How to create Event - clear. How to send - no. Should I check like "isServer". Should I write an event receiver on the entity? For example host press button->host changes integer variable in Player entity to 1,2 or 3. A very simple example, why there is no explanation. If the topic was clear in docs, no one would ask, maybe you should add smth like this in docs.0
-
Upd: after one hour searching forum I found post with this command:
//Find all objects for the leaving connection. EntityObjects = new List<BoltEntity>(); foreach (BoltEntity item in BoltNetwork.Entities) { EntityObjects.Add(item); }
And it helped me alot.
So u should create script on GameObject (i call it ServerManager) with event(Event creating is described in bolt docs) launching code:public void testEvent(){ if (BoltNetwork.IsServer) { var myEvent = _setClass.Create(EntityObjects[0]); myEvent._newClass = "civilian"; myEvent.Send(); myEvent = _setClass.Create(EntityObjects[1]); myEvent._newClass = "miner"; myEvent.Send(); //var myEntityEvent = _setClassForEntity.Create(entity); } }
and on Player entity:public override void OnEvent(_setClass evnt) { if (entity.IsOwner) { state._class = evnt._newClass; } }
0