Skip to main content
annap90227144
Inspiring
May 3, 2019
Answered

Fire action on every keyframe

  • May 3, 2019
  • 1 reply
  • 741 views

I want drive change of effect property on every keyframe: it would change its value from 0 to 1 and vice versa (basically on & off).

So far I have this expression for the effect "Dust & Scratches" sitting on its "Threshold" property:

var v = 1;

var n = timeRemap.numKeys;

if (n > 0){

    if(time < timeRemap.nearestKey(time).time){

        if(v == 0){

            v = 1;

        }else{

            v = 0

        }

    }

}

v

Problem is I would like to be able fire the change exactly on every new keyframe but I am not able to get there, this is the closest but of course it changes the value "erratically" once it reaches middle point between two frames.

I tried also this but to no success too as the variables kfA/kfB are initialized with every frame 😞

var kfA = 1;

var kfB = 2;

var v = 1;

var n = timeRemap.numKeys;

if (n > 0){

    if(time >= timeRemap.key(kfA).time && time < timeRemap.key(kfB).time){

        if(v == 0){

            v = 1;

        }else{

            v = 0

        }

    }

    if(time == timeRemap.key(kfB).time){

        kfA++;

        kfB++;

    }

}

v

This topic has been closed for replies.
Correct answer Paul Tuersley

I posted this in your other thread but as suggested, posting it here too. Apply it to the Threshold property of the Dust & Scratches effect.

Glad to hear it works!

a = timeRemap;

nearestKey = a.nearestKey(time).index;

if (time < a.key(nearestKey).time) nearestKey --;

if (nearestKey/2 != Math.round(nearestKey/2)) 0;

else 255;

Translation for the above would be:

grab the timeRemap property for this layer

find the index of the nearest remap keyframe at the current time (expressions are recalculated on each individual frame)

if the current time is earlier than the nearest keyframe, reduce 'nearestKey' by 1 so we're always considering the keyframe before the current time.

if keyframe is an odd value (i.e. if value divided by 2 doesn't equal the same result rounded down) make the value 0, otherwise make it 255.

1 reply

Paul TuersleyCorrect answer
Inspiring
May 3, 2019

I posted this in your other thread but as suggested, posting it here too. Apply it to the Threshold property of the Dust & Scratches effect.

Glad to hear it works!

a = timeRemap;

nearestKey = a.nearestKey(time).index;

if (time < a.key(nearestKey).time) nearestKey --;

if (nearestKey/2 != Math.round(nearestKey/2)) 0;

else 255;

Translation for the above would be:

grab the timeRemap property for this layer

find the index of the nearest remap keyframe at the current time (expressions are recalculated on each individual frame)

if the current time is earlier than the nearest keyframe, reduce 'nearestKey' by 1 so we're always considering the keyframe before the current time.

if keyframe is an odd value (i.e. if value divided by 2 doesn't equal the same result rounded down) make the value 0, otherwise make it 255.

annap90227144
Inspiring
May 3, 2019

Thank you once again!