A note on optimization!

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.

1 Like

Thanks for sharing that. I’ll have to have a look as it has been a while since I’ve dug through the code itself and I may give it a try.

I do know from discussions from various instructors that they often follow sub-optimal processes to facilitate easier teaching which I respect. We often get people suggesting more optimal solutions or, the one I hate the most personally is ‘Best Practices’ which is always subjective. In this case I think you may be on to something as it is still a nice simple solution. I assume you’ve tried this yourself and it works just fine/the same as the original code? I can’t think of a reason why it wouldn’t tbh.

Usually I would say, if it ain’t broke don’t fix it but also development is iterative. You get things working the way you want and test it thoroughly and if you want to optimise, iterate with small changes and retest to ensure the code still works.

Could you perhaps share here the code for others so if they wish to try this approach, they can. Thanks.

Privacy & Terms