Skip to content

Instantly share code, notes, and snippets.

@animoplex
Created March 7, 2019 21:23
Show Gist options
  • Save animoplex/fa91659baccbb91b810313053a48c2e9 to your computer and use it in GitHub Desktop.
Save animoplex/fa91659baccbb91b810313053a48c2e9 to your computer and use it in GitHub Desktop.
Loop Animation With Markers - After Effects Expression by Animoplex
// Loop Animation With Markers - Created by Animoplex: www.animoplex.com
// Repeat a property's keyframed animation, resetting the loop at the start of every layer marker
// Based loosely on Marker Sync Expression: http://www.motionscript.com/design-guide/marker-sync.html
n = 0;
if (marker.numKeys > 0) {
n = marker.nearestKey(time).index;
if (marker.key(n).time > time) {
n--;
} // get previous marker index
}
if (n == 0) {
value;
} else {
m = marker.key(n); // m is target marker
t = time - m.time; // time since target marker
try {
valueAtTime(key(1).time + t); // play from first keyframe
} catch(err) {
value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment