In this lecture, Sam has us both creating the Spline and running interpolations in ClientTick
, but the values stored in the FHermiteCubicSpline
struct only ever change on Server updates.
It’s a small optimization to be concerned with given there’s only a few calculations occurring, but I’d recommend creating the Spline in SimulatedProxy_OnRep_ServerState
and storing in a private variable instead of creating an identical Spline struct every time ClientTick
is called. You’ll also probably want to store VelocityToDerivative
in a private variable and set it just before the spline is created.
Then you can run the interpolations on the already created Spline with the changing LerpRatio
in ClientTick
.
I know Unreal’s compiler is great at optimizing code, but I’m not sure this case would get optimized out or not. In any case, I’d argue it’s a good practice to try to recognize easy optimizations that can be made in code and handle them before they get out of hand.