The Expressions Cheat Sheet

nearestKey() lets you get the value of the keyframe that is closest to the specified time.


Passing in the variable "time" will get the key that is closest to the time indicator.

Removing keyframes transition (simulating "hold" keyframes)

Let's say we want to temporarily remove the transition between your keyframes. You could right-click your keyframes and choose "Toggle Hold Keyframes" which will do just that, but this method is destructive and you can lose your previous easing data that way.

To get around this issue we can simulate the same effect using an expression, by finding the last keyframe and sticking to its value.

var nearest = nearestKey(time); // get the key closest to the current time
var isInThePast = nearest.time <= time; // ask: is it in the past? true / false
isInThePast ? nearest : key(nearest.index-1); // if it is use it, otherwise get the one before it

Now we can remove / disable the expression in case we want to go back to our original keyframe data.