How do you call high-priority RPCs that need to activate at a certain point in an animation?

What’s the best way to execute server-side code that is supposed to trigger at a certain point in an animation? For example, if I want to damage a character right when another character swings their sword, how would I do that, without using any built-in features like GAS?

The obvious solution would be to have an animation notify and damage the character when that notify is called. But the problem is that since every client plays that same animation locally, every single one would call the server RPC, and end up damaging the character a bunch of times.

The best solution I could imagine would be skipping the RPC and just making the server damage the character when it reaches the notify. But unless you’re using a listen server, the server won’t play the animation, and therefore can’t call the notify.

This seems like a really simple problem and I’m just too dumb to figure it out, but I can’t find any examples that are related to my specific project. How could I solve this?

But the problem is that since every client plays that same animation locally, every single one would call the server RPC, and end up damaging the character a bunch of times.

Normally only the local player should call the server rpc so when one player swings only one rpc should be sent to the server to apply the damage when the notify is hit.

Also a dedicated server can play montages so I’m not sure what you mean by server won’t play the animation.

2 Likes

Also a dedicated server can play montages so I’m not sure what you mean by server won’t play the animation.

Oh… well that’s very helpful information that I was not aware of. So in big games that have things like gameplay abilities, would the actual affects of those abilities (like tracing and dealing damage with a hitscan weapon) be performed with an animation notify on the server? Or is there some other stuff going on?

It depends on how you want to deal with latency, you can play the montage on server and handle the notify there as well and of course server side do your tracing and apply damage, I’ve seen some example where a timer is used instead of a notify, the timer executes a function which replaces the notify trigger.

You can also do the trace client side and send the hit result to the server, this is mainly to give the player a smooth experience and avoid cases where you think you hit someone but server side their location is slightly off so the server trace doesn’t hit, similar to some shooters where they do weapon damage client side. This method usually has some extra server validation to ensure the action is actually possible.

2 Likes

Cool, thanks!

1 Like