Question RE: Cost of starting/stopping tasks

'lo again.

I’ve got a task running in my game which updates the rotation of the character model gradually over time (i.e. a smooth transition when changing direction).

This task currently runs constantly so I’m thinking of having it stop when the rotation is complete and restart on new input - so I’m wondering whether this would be a bad idea, if there’s any significant overhead to starting/stopping tasks versus leaving the task running even if/when it has nothing to do.

(Or perhaps I’ve missed a better solution to the problem altogether)

Thanks in advance.

This sounds like a job for intervals. In particular, the LerpHprInterval.

If you want to keep going with tasks, having one long running task versus starting and stopping probably wont make much of a difference.

If you were to use tasks instead of intervals, you could have a task constantly check for a target rotation and whether it matches the current rotation, and if not, rotate towards the target rotation.

I would personally just keep it running for the sake of simplicity and only consider optimizing if you notice that this is having a measurable impact on frame time (which I expect it won’t).

Thanks for the replies. I’ll just leave the task running for now.

The reason I’m using a task instead of an interval is because the target angle may change before the transition is complete (e.g. if the player changes direction mid-rotation) - for which I imagine it’s better to have one task handle the rotation, than either starting/stopping intervals or creating multiple intervals for every change of angle and lerping between them. I could be wrong on that.

Yeah, makes sense, and I would have probably used a task too for that purpose, though it can be done with intervals too.