Clear individual buffered RPC calls

The whole answer can be found below.

Please note: The Photon forum is closed permanently. After many dedicated years of service we have made the decision to retire our forum and switch to read-only: we've saved the best to last! And we offer you support through these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

Clear individual buffered RPC calls

Duck
2020-11-03 22:52:16

Hello everyone,
is there a way to clear an individual buffered RPC call from the cache? I don't want to clear the whole cache of a PhotonView, but rather only one buffered RPC call.

I would be very happy if someone could clear that out for me.

Thank you already in advance

PS: I have another little problem and I wonder if there is another way to solve it than passing a Vector3 array in an RPC/RaiseEvent.
If a player doesn't move or rotate in the moment the new player joins, his position and rotation are not being synchronized with the new player who just joined the room. It stays like this until the player moves, then he suddenly appears and that looks extremely weird and it's not the desired effect.
I know I could change the Observe option in the Photon View component, but I don't really want that because it unnecessarily increases the traffic and the Messages. Unreliable on Change works very well for me but the only problem with this is when a new player joins the room and a player stands still.
My question: Is there a way to synchronize the players position and rotation just once (for the new player) if he doesn't move? I could pass a Vector3 array and a float array (since the player just rotates on one axis) in an RPC and send that to the new player when he joins, but is there a better way?

Thank you already in advance

Comments

JohnTube
2020-11-04 14:26:39

Hi @Duck,

is there a way to clear an individual buffered RPC call from the cache? I don't want to clear the whole cache of a PhotonView, but rather only one buffered RPC call.

Add this to PhotonNetworkPart.cs:

 public static void RemoveBufferedRpcs(PhotonView view = null, string methodName = null, int[] callersActorNumbers = null, params object[] parameters)  
        {  
            Hashtable filter = new Hashtable(3);  
            if (view != null)  
            {  
                filter[keyByteZero] = view.ViewID;  
            }  
            if (!string.IsNullOrEmpty(methodName))  
            {  
                // send name or shortcut (if available)  
                int shortcut;  
                if (rpcShortcuts.TryGetValue(methodName, out shortcut))  
                {  
                    filter[keyByteFive] = (byte)shortcut; // LIMITS RPC COUNT  
                }  
                else  
                {  
                    filter[keyByteThree] = methodName;  
                }  
            }  
            if (parameters != null && parameters.Length > 0)  
            {  
                filter[keyByteFour] = parameters;  
            }  
            RaiseEventOptions raiseEventOptions = new RaiseEventOptions();  
            raiseEventOptions.CachingOption = EventCaching.RemoveFromRoomCache;  
            if (callersActorNumbers != null)  
            {  
                raiseEventOptions.TargetActors = callersActorNumbers;  
            }  
            PhotonNetwork.RaiseEventInternal(PunEvent.RPC, filter, raiseEventOptions, SendOptions.SendReliable);  
        }

use it PhotonNetwork.RemoveBufferedRpcs() and specify the parameters you need.
Each parameter is a filter for which buffered RPCs you want to remove.
All parameters are optional.
If you do not pass any filter parameters, all buffered RPCs will be removed.

My question: Is there a way to synchronize the players position and rotation just once (for the new player) if he doesn't move? I could pass a Vector3 array and a float array (since the player just rotates on one axis) in an RPC and send that to the new player when he joins, but is there a better way?

I would search the forums or ask in a separate thread.

Duck
2020-11-04 23:21:23

Hello @JohnTube . The code you sent definitely does make sense.
The only two things I'm a little bit unsure about is the third parameter (the int-array callersActorNumber) on the one hand...
Are these the players who will receive this and correspondingly remove the RPC from the buffer? And if I don't pass anything, the RPC will be removed from the Buffer for every player, is that right?
And on the other hand, I'm not quite sure about the parameters. Are these the parameters of the RPC method? What if I don't pass anything or some values that do not match with the parameters passed in the actual RPC?

I would be very happy if you could clarify that.

Again, thank you very much for your help and effort, I really appreciate it.

JohnTube
2020-11-05 10:11:35

Optional parameters guide:

  • PhotonView view: the PhotonView where the RPC has been called on. We actually need its ViewID. If none is provided all PhotonViews/ViewIDs are considered.
  • string methodName: the RPC method name, if possible we will use its hash shortcut for efficiency. If none is provided all RPC method names are considered.
  • int[] callersActorNumbers: the actor numbers of the actors who called/buffered the RPC. For example if two players buffered the same RPC you can clear the buffered RPC of one and keep the other. If none is provided all senders are considered.
  • object[] parameters: the parameters used when calling the buffered RPC. For example if you buffered the same RPC multiple times with different parameters each time, then you can choose which one to remove from the buffer. If none is provided all parameters are considered.

Duck
2020-11-05 12:26:17

Thank you very much for your answer. That's pretty much what I assumed. I understand it a lot better now.

Thank you for your effort, I really appreciate it.

Back to top