Pun 2 RemoveFromRoomCache for only local player
Options
Hi team,
I would like to clear the received event for only the local player when in case of disconnection and he is reconnected but I don't want him to receive the old events which are already executed.
I tried the following method when I receive and execute the event, but it looks like it clears the event for all the players.
What is the correct suggested approach to using "RemoveFromRoomCache"?
I would like to clear the received event for only the local player when in case of disconnection and he is reconnected but I don't want him to receive the old events which are already executed.
I tried the following method when I receive and execute the event, but it looks like it clears the event for all the players.
RaiseEvent(photonEvent.Code, photonEvent.CustomData, new RaiseEventOptions() { CachingOption = EventCaching.RemoveFromRoomCache, TargetActors = new int[] { PhotonNetwork.LocalPlayer.ActorNumber } });
What is the correct suggested approach to using "RemoveFromRoomCache"?
0
Comments
-
[Edit]
Here is the CachingOption used.new RaiseEventOptions() { CachingOption = EventCaching.AddToRoomCache, Receivers = ReceiverGroup.All }
I am trying to use just object<T> in customData. Does that affect how the filter works? Somewhere I read it works only if hashtables are used
tried the following as well with no luckRaiseEvent(0, (Hashtable)photonEvent.CustomData, new RaiseEventOptions() { CachingOption = EventCaching.RemoveFromRoomCache, });
If a player gets reconnected old events are fired again.
here is the common RaiseEvent methodpublic void RaiseEvent(byte eventCode, object content, RaiseEventOptions options) { Hashtable hash = new Hashtable() { { "data", content } }; PhotonNetwork.RaiseEvent(eventCode, hash, options, SendOptions.SendReliable); PhotonNetwork.SendAllOutgoingCommands(); }
0 -
Hi @Sathyaraj,
Unfortunately you cannot remove cached events based on the receiving actor.RaiseEvent(photonEvent.Code, photonEvent.CustomData, new RaiseEventOptions() { CachingOption = EventCaching.RemoveFromRoomCache, TargetActors = new int[] { PhotonNetwork.LocalPlayer.ActorNumber } });
What you have tried here is removing all events that are cached (raised/sent) by the local actor.I don't want him to receive the old events which are already executed
- make each even unique (assign auto increment event ID?) or add meta data to event payload, anything to be able to identify received events
- locally store (client cache, file or memory) information of already processed events (last processed event ID for example)
- when an event is received, check if it's already processed or not, if it's already processed ignore it
About what data types/structures that can be used as filters, I will have to check if we support other types than Hashtable.0 -
@JohnTube
string data = (string)((Hashtable)photonEvent.CustomData)["data"]; string time = (string)((Hashtable)photonEvent.CustomData)["time"]; string eventStr = $"{photonEvent.Code}{photonEvent.Sender}{time}"; if (!_receievedEvents.Contains(eventStr)) { _receievedEvents.Add(eventStr); //TODO: Process event }
This crude method works as expected. But hoping to find a better-optimized solution from experts.
Did anyone go through such use case?0 -
I think the solution is fine.1
-
Hello Sathyaraj, I'm also facing the same problem.
Please tell me how do you solved it with code.
thanks0 -
nilesh123shripal wrote: »Hello Sathyaraj, I'm also facing the same problem.
Please tell me how do you solved it with code.
thanks
Use the following line in OnEvent method to cache it in a list. Clear it when the game is over.
HashSet<string> _receievedEvents = new HashSet<string>();
//inside OnEvent
string data = (string)((Hashtable)photonEvent.CustomData)["data"];
string time = (string)((Hashtable)photonEvent.CustomData)["time"];
string eventStr = $"{photonEvent.Code}{photonEvent.Sender}{time}";
if (!_receievedEvents.Contains(eventStr))
{
_receievedEvents.Add(eventStr);
//TODO: Process event
}0