Events not caching in room?

I am trying to send events that are added to the Room Cache but no one that is joining late is receiving them. Whenever those events are sent with players in the room all works well, but nothing with later joining players.


This is the way I am doing it, nothing strange I think here. And not sure how to debug further.

Comments

  • I have some thoughts, but not sure how to address properly if so. This class above that does the events doesn't get registered to the Network (PhotonNetwork.AddCallBacktarget(this);) until a couple frames have happened and a few things have initialized to the scene so maybe this event is being missed by new players joining since it's being sent before this gets registered? Is there a way to receive those "again" or check if that's the case? I wouldn't want to roll my own system for caching these if possible.

  • Meep
    Meep ✭✭✭

    You should register your OnEvent handlers before joining a room or at least in the OnJoinedRoom callback. This is standard practice unless you want to miss things.

    Also, you're using the non-global version of event cache. So whenever the original sender leaves the room, the cached event will be released unless CleanupCacheOnLeave is disabled. If you need this event to persist even after the original player has left then make sure to use the global variant.

    If you wish to check whether you are receiving your event on joining, you can add a quick static callback before joining to debug it:

    PhotonNetwork.NetworkingClient.EventReceived += (info) =>
    {
       if (info.Code == /*Event code here*/)
       {
           Debug.Log("Received cached event");
       }
    };
    
  • Right, I understand that but there is a very specific reason for not having those register before joining a room. It's a complex fully dynamic system where even I register by hand each and all photonviews, so unfortunately I can't do that. I might have to cache it manually as well if there is no way to "re-receive" those cached events

  • In multiplayer games, you create a lot of problems, when you are unable to handle events at the time they arrive.

    If you only need a break until the scene is loaded and initialized, you can try to useIsMessageQueueRunning to control dispatching of events: RPCs and Events. This will pause all events, which might also not be what you need.

    Alternatively you could use Custom Properties to store your custom instantiation info. Those are synced asap when you join a room but unlike events, these are cached anyways, so you can use this info to instantiate your objects whenever you feel like it.