Client to Server RPC

For values that need to be updated immediately through an RPC, is it preferable to update the value on the client then call a server RPC to do the same? Could this create a run condition where the client tries to set a variable that’s different on the server?

Or, Is it better to call a server RPC and then have the server initiate a client RPC back to the calling client?

Take something as simple as stamina. I’m conflicted on which of the two implementations to use.

It depends on the importance of that variable in terms of what it offers to the client if the client is allowed to set it client side. I have a similar situation but with a bIsAiming boolean variable, I have this variable replicated but in the replication condition I have set to skip owner so that I can set it to true and then let the server know, the server then sets that variable to true as well and it gets replicated to all clients except for the owner because I already set it.

In this case it makes sense for me to set it to true immediately because otherwise the aiming animation will be delayed if I have to wait for the server so in order to keep things smooth that variable has to be set client side immediately.

Also you said that you need to use an RPC to update it immediately, a replicated variable is not as slow as you might think, if the variable needs to be replicated to everyone then I suggest making it replicated instead of using something like a multicast.

Hi, thank you for the reply!

I’ll use replication for these events. I think it will be quick enough in 99% of the scenarios. Thank you.