Download

Running the same function on client and server independently

I have an actor called Ability. It have attached State Machine component, which is used to control state of ability, like casting or cooldown.

Now. I run state twice. On client and on server. There is no real synchronization between those two. When input is received that state is just changed on both client and server independently.

It have advantage of the client getting accurate approximation to current timers (casting time, cooldown time), and feeling of instant feedback when button has been pressed.
In any case the client side things are used purely for cosmetic stuff. Entire game mechanics (like tracing, damage) is run on server and results are replicated back to client. And things that need to be synced between clients are called by using NetMulticast functions.

Now my question, is this an good approach or should I think about something else ?

It’s a valid approach, however the client cooldowns could get out of sync with the server ones pretty easily if there’s lag. If that happens, it’s possible that the client could activate an ability, see an effect, however the server thinks the ability is still on cooldown. You could improve the synchronisation by requiring the server to respond to clients when an ability has been successfully activated/deactivated, however you’d have to accept a little input lag then.

I think there would need to be some level of checking to make sure stuff is in sync, common things that get out of sync are time, especially if you have abilities that are time based like buffs or channel based spells. I think showing the visuals on the client right away are fine but I think in the case of multiplayer games unless all players are playing locally within the simulation I would worry about stuff getting out of sync when you have things like lag or timing is off.

Thanks guys.
I reworked it a bit, and now it works bit differently:

  1. I apply effect on server.
  2. Replicate single bool, to indicate if it is appiled.
  3. Then client run timer independently of server.
  4. When timer on server finish it sends bool again to terminate the one on client.

It includes bit of latency, but there shouldn’t be any synchronization problems anymore.