How to Loop Animations in After Effects with Expressions
Creating seamless, infinite loops in Adobe After Effects saves time
by eliminating the need to duplicate keyframes manually across your
timeline. By using simple built-in expressions like
loopOut(), loopIn(), and time-based code, you
can automate repetitive motion for properties such as position, scale,
opacity, and rotation. This guide covers the primary looping
expressions, their parameters, and step-by-step instructions to
implement them efficiently.
The loopOut() Expression
The loopOut() expression is the most common method for
creating infinite cycles. It tells After Effects to repeat the keyframed
animation continuously after the final keyframe is reached.
How to Apply It
Animate any property (e.g., Rotation or Position) using at least two keyframes.
Hold Alt (Windows) or Option (macOS) and click the stopwatch next to the property.
In the expression field that appears, type:
loopOut();Click anywhere outside the text box to activate the code.
By default, typing loopOut() executes
loopOut("cycle", 0).
Understanding Loop Types
You can customize how the animation behaves by adding specific loop types inside quotation marks within the parentheses:
- Cycle (
loopOut("cycle")): Restarts the animation from the first keyframe as soon as the last keyframe is reached, creating a standard repeating loop. - Ping-Pong (
loopOut("pingpong")): Plays the animation forward from the first to the last keyframe, then plays it backward to the start, continuously bouncing back and forth. - Offset (
loopOut("offset")): Continues the motion by adding the value change between the first and last keyframe to each subsequent loop. This is ideal for progressive motion, such as a character walking across a screen or a staircase climb. - Continue (
loopOut("continue")): Extends the velocity of the last keyframe into the future at a constant speed rather than repeating the keyframed sequence.
Controlling Keyframe Ranges
The second argument in the expression controls how many keyframes are included in the loop:
loopOut("cycle", 1);- A value of
0loops all keyframes on the property. - A value of
1loops only the final segment between the last two keyframes. - A value of
2loops the segments across the last three keyframes.
Looping Before Keyframes: loopIn()
While loopOut() repeats animation after the final
keyframe, loopIn() repeats animation before the first
keyframe occurs.
Syntax:
loopIn("cycle")orloopIn("pingpong")Combining both: To loop an animation infinitely across the entire composition regardless of where the playhead is relative to your keyframes, combine them:
loopIn("cycle") + loopOut("cycle") - value;
Continuous Loops Without Keyframes
For linear, unending movement such as rotating gears, clock hands, or
background scrolling, expressions using the time variable
eliminate the need for keyframes entirely.
Apply the following to any property to create constant speed based on seconds:
time * 180;In this example applied to Rotation, the layer rotates 180 degrees every second indefinitely.
Creating a Seamless Looping Wiggle
The standard wiggle() function produces random motion
that does not repeat naturally. To force a wiggle into an exact,
seamless loop over a set duration, use the following expression:
freq = 1;
amp = 50;
loopTime = 3; // Length of loop in seconds
t = time % loopTime;
w1 = wiggle(freq, amp, 1, 0.5, t);
w2 = wiggle(freq, amp, 1, 0.5, t - loopTime);
linear(t, 0, loopTime, w1, w2);Adjust loopTime to match your composition's duration to
ensure the random wiggle seamlessly restarts at the end of the
timeline.