Last connected client not receiving event
Options
I have this code:
The event is always and only sent from the MasterClient.
public void BroadcastMessage(Message message, bool sendReliable, bool includeSelf) { var raiseEventOptions = RaiseEventOptions.Default; if (includeSelf) { raiseEventOptions.Receivers = ReceiverGroup.All; //raiseEventOptions.TargetActors = PhotonNetwork.playerList.Select(x => x.ID).ToArray(); } Debug.Log("Broadcasting message"); PhotonNetwork.RaiseEvent(message.Code, message.Contents, sendReliable, raiseEventOptions); }I'm testing on 3 connected machines. For some reasons, whichever player connects last is not getting the event.
The event is always and only sent from the MasterClient.
0
Comments
-
So not even 2 minutes after posting this I managed to fix it by adding this code after the if statement:
else { Debug.Log("Broadcasting message to others."); raiseEventOptions.TargetActors = PhotonNetwork.otherPlayers.Select(x => x.ID).ToArray(); }
The code then becomes:public void BroadcastMessage(Message message, bool sendReliable, bool includeSelf) { var raiseEventOptions = RaiseEventOptions.Default; if (includeSelf) { Debug.Log("Broadcasting message to all."); raiseEventOptions.Receivers = ReceiverGroup.All; //raiseEventOptions.TargetActors = PhotonNetwork.playerList.Select(x => x.ID).ToArray(); } else { Debug.Log("Broadcasting message to others."); raiseEventOptions.TargetActors = PhotonNetwork.otherPlayers.Select(x => x.ID).ToArray(); } PhotonNetwork.RaiseEvent(message.Code, message.Contents, sendReliable, raiseEventOptions); }
This is the only change I made. I'm not sure why sending the message to all players separately works because according to the docs, RaiseEventOptions.Default.Receivers == Others.0 -
Hi @rafael_at_jags,
Yes the method should work out of the box usingReceiverGroup.Others
. Are you sure you sent the event to that joining actor after he finished joining? If you want events to be received even for later joining ones you could make use of caching.0 -
Hi @JohnTube , Yep, I set it up so the event is launched whenever I press the "Q" key on my keyboard. I made sure that the state said "Joined" before pressing the key (I have the current connection state displayed in an OnGUI callback).0
-
bump0
-
@JohnTube , another thing I to keep in mind in that the second version I posted work. If not all players were in the room, then it wouldn't work for those players.0
-
Hi @rafael_at_jags,
As I mentioned before, sending an event to all current other players' IDs is the same as sending toReceiverGroups.Others
.
The issue is most likely a timing issue where you send an event from MasterClient while some actors did not finish joining yet.
You can wait until everyone has finished joining or cache the event so it will be received by players who join later.
In order to check if all players has finished joining:void OnPhotonPlayerConnected(PhotonPlayer otherPlayer) { if (PhotonNetwork.otherPlayers.Length == maxPlayers - 1) { BroadcastMessage(); } }
If you want to cache the event:raiseEventOptions.CachingOption = EventCaching.AddToRoomCache;
0