Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Reset time remap to 0 after every slider keyframe

  • Reset time remap to 0 after every slider keyframe

    Posted by Ben Waflik on March 25, 2023 at 2:27 pm

    Hi guys, so imagine I’ve enabled time remapping on a layer and its value changes with time as it supposed to. That’s fine by me, but I’d like to make it start playing back from 0 every time time reaches a slider keyframe. I’ve tried using modulus %, but the best thing I could find is nearestKey.time, which isn’t precise and affects time remapping sooner then there is a slider keyframe.


    Brie Clayton replied 1 year, 1 month ago 3 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    March 25, 2023 at 3:58 pm

    Try it this way:

    s = effect("Slider Control")("Slider");
    t = time;
    if (s.numKeys > 0){
    n = s.nearestKey(time).index;
    if (time < s.key(n).time) n--;
    if (n > 0) t = time - s.key(n).time;
    }
    valueAtTime(t)
  • Ben Waflik

    March 27, 2023 at 6:37 pm

    Works perfectly! I’m so happy I couldn’t believe my own eyes, Dan, thank you so much! Seriously, this expression opens so many doors for me now that I can reset time when I need. I was loosing hope it is possible with keyframes, all those tutorials on triggering time talk about markers only.

    I’m also wondering, is this what’s called “function” within this expression? I can sort of understand what I’m reading, except the “n–” part. What does it do? My guess is that it tells to repeat the if statement multiple times. I’d like to learn more about functions, they seem to hold great power, though there isn’t much examples of practical uses of them on the web as far as I know.

    Anyway, big thanks to you again, I’ll go checkout that Tip button on motionscript 🙂

  • Dan Ebberts

    March 27, 2023 at 7:01 pm

    A function will actually have the reserved word “function” as part of its definition so no, this isn’t a function.

    The n– is just part of the logic to make sure we end up with the most recent, previous keyframe. It’s necessary because nearestKey can retrieve a keyframe that is in the future, if that happens to be the one that’s closest to the current time, but we need to base the animation timing on the most recent keyframe from the past.

  • Brie Clayton

    March 28, 2023 at 7:58 pm

    Thank you, Dan!

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy