Learn how to create seamless, continuous animations in After Effects using expressions instead of duplicating keyframes. This article explains how a simple line of code can loop your animation indefinitely with ease and flexibility.
Key Insights
- After Effects allows you to loop animations using expressions, specifically the loopOut() function, eliminating the need to manually duplicate keyframes.
- Expressions in After Effects serve as a scripting language similar to JavaScript and are commonly used to automate repetitive animation tasks like looping, randomizing movement, or generating continuous change.
- Noble Desktop introduces the concept of using expressions in After Effects, focusing on the loopOut() method with a default "cycle" mode to repeat animations seamlessly after the last keyframe.
Note: These materials offer prospective students a preview of how our classes are structured. Students enrolled in this course will receive access to the full set of materials, including video lectures, project-based assignments, and instructor feedback.
By the way, that video I showed you of this only has three keyframes, the keyframes we just made. The entire animation is made with only three keyframes. We are going to use a feature in the program that allows us to loop those keyframes so they'll play forever, because technically, they don't.
They play once and they stop. There can be no animation prior to your first keyframe on the timeline. There is no animation after your last keyframe on the timeline.
Okay, that's just how the universe works. Unless, unless, unless, unless. This is 5b by the way.
This is page, sorry, wait a minute, 134 at the top, looping an animation with expressions. Okay, so if I want to repeat this animation over and over again, I could try and copy and paste many keyframes. Trust me, it wouldn't work very well, so don't do that, okay.
So, what I can do is loop it using code. So, there are two ways to animate stuff here, keyframes and code. Oh, oh, I'm looking at your faces.
Oh, code, code, it's horrible, he's evil. Yeah, whatever, okay. So, it's code, but we're gonna, it's one word, okay, it's one word.
It's code. So, basically, expressions are the scripting language of After Effects. They are similar to JavaScript, but they're not exactly JavaScript sort of thing, okay.
Now, there are people who specialize in it, there are books on it, there are websites devoted to it, and that sort of thing, okay. Most After Effects users who use the program a bit know maybe four things, loop out, wiggle, which randomizes stuff, random, which randomizes stuff even more, and how to, like, multiply things by times so that things will just keep increasing in value, okay. So, basically, four things.
People who specialize in it can do a lot more cool stuff, okay, definitely, okay, but this is, like, basically what it's for, okay. Now, some expressions are designed to replace keyframes. So, like, random, for example, would be used instead of using keyframes.
Some, like, loop out only work if you have keyframes. They loop the animation. It's called loop out because it starts to loop after the last keyframe, okay.
Technically, by the way, it's not going to loop into, which would work before the first keyframe happened, basically, but this is the keyframes at the beginning, so it's fine. So, if we loop out this, it'll just keep playing over and over again. So, two seconds, moves, repeats again, two seconds, moves, seconds, moves, so far, that's what it does.
There are different kinds of loops. We're going to use the default one, which is called a cycle, so this plays it over and over again. There's one called ping pong, plays back and forth, which would not make any sense in this case, but it's kind of fun, okay.
Now, in After Effects, help expression reference will open up the After Effects help page to the expression section, and there's a tutorial on looping with expressions, okay. So, it's a very common thing to do to do this. Now, here's how you do it, okay.
So, first of all, any property that has a stopwatch can have keyframes and expressions added. If you hover over the stopwatch icon, the program gives you a little tooltip telling you click to toggle animation, option click, or on Windows, ALT click to add or remove an expression, okay. So, I'm holding down option.
I click on the stopwatch here. The numbers turn red, indicating there's an expression. It opens up this little arrow expression for position, and underneath the keyframes is where you actually type the code of the expression.
The text field is here. It gives you some dummy text, which you got to delete, because it doesn't do anything, okay. Delete, delete, okay, backspace.
Step three says type the words loop out. Now, it's going to hint it for you, by the way. So, if you start typing loop, it'll give you a list of what it thinks you want to do, and you can just pick it from the list, okay.
Pick it from the list, because that way you'll avoid typos, because one of the most common errors, the most common error in coding are typos. Coding is case-sensitive and spelling-sensitive. So, if you misspell something, including miscapitalization, it will fail, okay.
Loop. Why is my keyboard not working? That's weird. Loop, loop.
Loop in, no. Loop in duration, no. Loop out, loop out duration.
It's going to say loop out. So, I highlight it. By the way, up and down arrow keys go up and down the list, by the way.
Return on my keyboard or enter, or just double click that highlighted word. It writes it out for you, okay. The instructions, step three, have some words you can put in the quotes.
You don't need to do that. End of the line, tap semicolon. Semicolon, by the way, is optional.
So, if you don't include it, you're fine, too. You don't need the words in the parentheses. The words in the parentheses, which will say cycle in the book, are the default way it loops.
So, if I don't include them, it's fine. But if I wanted to override the default behavior, I may hit back and forth like ping pong. I'd have to type something in there, okay.