Increment a number, based on number of keyframes in After Effects? I'm working on a video comparing old and new games, and I'm scrubbing through some footage frame by frame trying to count button inputs in DOOM over a period of time. I was wondering if there was a way to increment a number based on the amount of keyframes present. So ideally it would automatically go up by one for each keyframe placed on the timeline, without having to manually increase the value on a per keyframe basis. Is there an easy way to go about this or will I have to manually set the value per keyframe?

I've never really used expressions before so this is new territory for me, and I don't know where to start.

Thank you.
Yep, just do



var p = &lt;pick whip the property with the keyframes here&gt;;
var k = p.nearestKey(time);
if (k.time &lt;= time){
    k.index; //key is in the past
} else {
    k.index-1; //nearest key is in the future, return the previous key
}


On the first line you have to reference the property with the keyframes. The easiest way is with the pick whip (the curly thing in the expressions buttons). Drag it to the property you want to reference.



So the first line should look something like this:

var p = thisComp.layer("Pale Gray-Magenta Solid 2").effect("Slider Control")("Slider");


or

var p = transform.position;


Don't forget the semi-colon at the end.