Loop Path Keyframes In After Effects - Expression
After Effects Expressions
Basic Looping Expression for Paths
loopOut("cycle");
This expression loops the path keyframes in a cycle.
Looping with Ping Pong Effect
loopOut("pingpong");
This expression plays the path keyframes forward and then in reverse, creating a ping pong effect.
Looping with Offset
loopOut("offset", 3);
This expression offsets the loop by a certain number of keyframes. In this case, it uses the last three keyframes.
What It Does
In After Effects, while you can easily loop properties like position, scale, or rotation using the built-in loopOut("cycle") expression, paths are a bit trickier. Animated paths have their own unique behavior, which doesn't gel with the default looping expressions. Imagine you've drawn a custom shape using the Pen tool (located at the top toolbar), and you've animated it to morph into another shape over time. Now, if you want this animation to repeat, you'd typically have to duplicate the keyframes manually, which isn't efficient.
How To Use It
You'll soon realize that looping animations can save you a ton of time, especially when working with path keyframes. Let's break this down step by step, so you can grasp the concept and apply it seamlessly in your projects.
Looping a Simple Two-Keyframe Animation
Let's say you've animated a path from frame 0 to frame 20. Here's how you can loop it:
- Select the First Keyframe: On your timeline, click on the first keyframe. You'll find this under the property where you've set your path animation, which is usually within a shape layer or mask.
- Copy the Keyframe: With the keyframe selected, press Ctrl+C (or Command+C on Mac).
- Position the Current Time Indicator (CTI): Move the CTI to double the distance of your second keyframe. In our example, since the second keyframe is at frame 20, you'd move the CTI to frame 40.
- Paste the Keyframe: Press Ctrl+V (or Command+V on Mac). You've now created a loop for your two-keyframe animation.
Looping Animations with More Keyframes
For animations with more complexity, say three or more keyframes, the process requires a bit more finesse:
- Select All Keyframes Except the Last: On your timeline, click and drag to select all the keyframes, then hold down the Shift key and click on the last keyframe to deselect it.
- Copy the Selected Keyframes: Press Ctrl+C (or Command+C on Mac).
- Determine the Gap: Look at the time difference between your last two keyframes. For instance, if the second to last keyframe is at frame 60 and the last one is at frame 70, the gap is 10 frames.
- Position the CTI: Move the CTI past the last keyframe by the gap you determined. In our example, you'd place the CTI at frame 80.
- Paste and Reverse: Press Ctrl+V (or Command+V on Mac) to paste the keyframes. Then, with the newly pasted keyframes selected, go to the top menu and choose Animation > Keyframe Assistant > Time Reverse Keyframes. This creates a "ping pong" effect, making your animation play forward and then in reverse.
The Expression Solution for Path Looping
For those who love diving into the nitty-gritty, there's an expression that can make this whole process even smoother. Expressions in After Effects are snippets of code that automate certain tasks. To apply this:
- Select Your Path Property: Click on the stopwatch icon next to the path property while holding the Alt key (or Option key on Mac). This opens the expression editor.
- Enter the Looping Expression: Here, you'd input a specific code that calculates the looping based on your keyframes. This code considers the start and end times of your animation and creates a seamless loop.
- Apply and Watch: Once the expression is in place, play your animation. You'll see that the path loops seamlessly without the need for manual keyframe duplication.