top of page
Marker-Based Animation Trigger
Advanced Expression, Animation Techniques, Time Based Animation, Transform
Marker-Based Animation Trigger
This expression triggers animations based on the most recent composition marker by offsetting keyframe timing relative to the marker. If no marker is active, it holds the initial animation value.
Imagine you have a bouncing ball animation in After Effects and want it to restart every time a composition marker is placed. Apply this expression to the ball’s position property. Place markers at different times in the timeline, and the ball's bounce will begin from the start of its animation at each marker. If no marker is present, the animation will hold its initial position value.
m = thisComp.marker;
if (m.numKeys > 0) {
triggerTime = 0;
for (i = 1; i <= m.numKeys; i++) {
if (time >= m.key(i).time) {
triggerTime = m.key(i).time; // Use the most recent marker
}
}
if (triggerTime > 0) {
timeOffset = time - triggerTime; // Calculate the offset based on the most recent marker
valueAtTime(timeOffset); // Adjust the property value
} else {
valueAtTime(0); // Hold the initial state if no markers have been reached
}
} else {
0; // No animation if no markers exist
}
How to Use This Expression?
Add Markers: In your composition, press
*
on your keyboard (numeric keypad) to add markers on the timeline where you want the animation to trigger.
Animate a Property: Create keyframes for the property you want to animate (e.g., position, scale, or opacity).
Apply the Expression: Select the property where you've created keyframes.
HoldAlt
(Windows) orOption
(Mac) and click the stopwatch icon next to the property.
Paste the expression into the text field that appears.
Adjust Animation Timing: Move the markers along the timeline. The animation will restart at the marker times.
This works for any property that supports keyframes and markers.
Trending
bottom of page