curve key tangent mode in runtime (or other way to make a value between two keys constant)

Hi,

I’m using a particle system with a calculated velocity over lifetime curve to make a wind effect that passes through some given waypoints. This require the particles to go in a fixed direction until they reach the next waypoint, then change to the next direction, etc… So I used AnimationUtility.SetCurveTangentMode (or SetKeyTangentMode) with the “constant” tangent mode and that works fine in the editor, but AnimationUtility is not available in builds.

How can I have the same result without AnimationUtility?
I tried looking for the reference code of these functions (UnityCsReference/Editor/Mono/Animation/AnimationUtility.bindings.cs at master · Unity-Technologies/UnityCsReference · GitHub) but those are external and I have no idea how they work… I undestand it has to do with inTangent and outTangent of the keys, however I could not find any values for those that would work.

Thanks in advance !

Okay so just in case someone find this looking for the same thing : it seems to work for me to have all keys inTangent to 0 and outTangent to float.PositiveInfinity…

If it doesn’t, try using AnimationUtility functions in the editor until it works, then log your keys inTangent and outTangent, and use those values

1 Like