Can't get Cached Events to trigger on rejoining a game

edited May 2016 in DotNet
Looked over the API (I am using the turnbased SDK) and the Cached Events Doc to try to get cached events implemented in our game for players that leave and rejoin, but it seems to only work partially? I'll get 2 events triggered upon a rejoin out of the 8-10 that triggered with "ExitGames.Client.Photon.Lite.EventCaching.AddToRoomCacheGlobal" as the caching option.

For the game itself, I am leaving via:

this.OpLeaveRoom (true);

Then rejoining via:
OpJoinRoom(room.Name, actorID);

re-using the actorID assigned to the client upon joining originally. One thing I wasn't clear on via the API was how fast the cached events arrive. I know they arrive in order, but are they just blasted at the client right after the Join event? Do they come under some other 'event code' (wrapped) or should they come as-is?

My symptom is that when i remove caching from the relevant event, I get nothing on rejoin (as expected). But once I enable it, I'll have 10-11 events supposedly cached, but only the first 2 I ever receive on rejoin via the OnEvent() method.

Other potential complications:
- I connect into the game room via 1 unity scene, and then load another unity scene after the join msg. during the load time I've got a background thread doing a 'SendAcksOnly()' on the loadBalancingPeer until the new scene is fully loaded. Could cached events be potentially dropped during this time or will the client buffer the events?


  • The cached event docs are on the "to update" list for quite a while. But we consider doing some extensions to that system first, so updates get delayed. Sorry.

    When you join a room, the client gets the properties first. This includes room and player properties.

    Next are the events that got buffered. They arrive in order before anything that is currently happening does arrive. There is no "end of buffer sign" built into the system but often buffered events should be using a different code and should do something specific (which means it's useful to buffer them).

    You can get events one by one by calling DispatchIncomingCommands(). Service() will call that in a loop until all received events are dispatched, so you lose some control.

    If one event tells you to switch a scene, you should dispatch one by one. Else, you begin to load a scene and Service() might dispatch events that belong to the scene you're loading right now.

    That might explain your "loss". Maybe you handle events in the old scene and then everything gets destroyed by the engine when you load.

    PUN implements this similarly. It dispatches one by one and stops immediately when something triggers PhotonNetwork.LoadScene(). It keeps a thread to call SendAcksOnly() and when the scene is loaded, it resumes calling SendOutgoingCommands() and DispatchIncomingCommands().

    You implemented OnEvent() somewhere - maybe you count the events in there and check if you got everything.
  • Thanks for the info Tobias! I've switched out the Service() call with my own update loop and disable the dispatching as soon as I get a ClientState.Joined state change and detect it's a rejoin, re-enabling it later when the proper scene is loaded. All the cached events are coming through now.

    Just one more question: does the photon Turnbased SDK destroy all currently "undispatched" events on a scene change internally? I couldn't tell if it was just how I arranged my SendAcksOnly() (basically removing all listeners to any incoming events) or if it was a feature of the SDK, so even if I was listening they'd get dropped anyway. My quick tests seem to imply they are dropped on a scene change but I wanted to confirm.


  • Photon does not have a concept of "scene change", so it's not doing anything when you do.
  • Hi Everybody,
    I am working on getting event cache on reconnect but I am also getting only one event, Did anyone worked on that. I am using AddToRoom and I am getting one event only. In my game I have two players only and the event I am getting is 1st event raised by the master player. Please explain me how I can do this.
  • If somebody disconnect temprarory and reconnect then still, all cache event's are removed from the server. ?
  • JohnTube
    JohnTube ✭✭✭✭✭
    edited January 2019
    Hi @ashishhellotech7,

    If somebody disconnect temprarory and reconnect then still, all cache event's are removed from the server. ?

    No, if an actor is temporarily disconnected (PlayerTTL != 0), its cached events are not removed.
    Those cached events will be removed when the actor leaves the room for good and DeleteCacheOnLeave/CleanUpCacheOnLeave is on.
  • Usually on second time reconnect I am getting failed, Is there any specific reason ?
  • JohnTube
    JohnTube ✭✭✭✭✭
    Hi @ashishhellotech7,

    Usually on second time reconnect I am getting failed, Is there any specific reason ?
    What do you mean? Can you share the logs of the exact error code and message you are having? Maybe you are calling Join instead of Rejoin or you are not setting a proper PlayerTTL value as I explained above.
  • I am using Rejoin and also I have also setup the PlayerTTL value, but it's not always reconnect.
    And I am also setup a self hosted server, and my client is also connected with them but I am not getting the log updated on server side in master and game log files.
    Can you help me on that also.
    My Second question is even after using Rejoin and setup PlayerTTL value 60Sec, not always I reconnect. Basically I am trying to do is in between the game I am switch off the wifi and on it withing 30sec but I am not always recconect to the server.