Streamline repetitive animations in After Effects using the versatile loopOut expression. This article breaks down how to apply loopOut to various animation scenarios, improving efficiency and flexibility while reducing the number of keyframes.
Key Insights
- The loopOut expression in After Effects repeats keyframes automatically, with three common behaviors—cycle, pingpong, and offset—each useful for different types of animation loops, such as continuous rotations or back-and-forth motions.
- Using loopOut significantly reduces the number of required keyframes, making it easier to adjust timing and easing, which ultimately simplifies the animation workflow and improves maintainability.
- Noble Desktop demonstrates how animators can efficiently control rotation and pacing through minimal keyframes and expressions, showing clear examples with a pendulum, minute hand, and hour hand animation setup.
This lesson is a preview from our After Effects Certification Course Online (includes software & exam). Enroll in a course for detailed lessons, live instructor support, and project-based training.
This is a lesson preview only. For the full lesson, purchase the course here.
So for this series of lessons, we'll be using the Intro to Expressions started file. It's found in the Intro to Expressions folder. As usual, I get a message about it being an older version.
I'll just say OK to that. I'm going to save my file, which will update it to the current version. My name, hyphen intro, or whatever you want to call it is fine.
There are three compositions in this project. Loop Out, Wiggle Me, and Randomize. Those are three that we'll be covering in this overall intro.
So let's start with Loop Out. So Loop Out is an expression that basically repeats keyframes, so it needs keyframes. Expressions are the scripting language of After Effects.
They are added to specific effects, and they can loop keyframes, they can add random motion, and do a lot of other things. They are based on the JavaScript language, though they technically aren't exactly JavaScript. And even though you don't necessarily have to learn the entire language, and that can take a long time, it is a programming language effectively, or a scripting language really, knowing a few simple expressions can really help optimize your workflow.
And that's what we're going to cover in this series of videos. So first, Loop Out. So Loop Out needs keyframes.
Without keyframes, it's going to cause an error. Some expressions work with keyframes, some replace keyframes, it varies. So the Loop Out expression first.
So first we need to make some keyframes. So I'm going to animate the pendulum, the minute hand, and the hour hand, and it's going to let me demo three of the different types of the Loop Out expression. Before I do this, I'm going to go to my After Effects settings.
If you're on Windows, it'd be Edit Preferences. I'm going to find the Scripting and Expressions section, and just to make it easier for this to show, I'm going to actually raise the size of the text to 24. It'll just make the text in the coding window just look bigger, so it's easier for you to see on your screen.
Okay, so now let's animate the pendulum. I need the anchor point on top, so I'll just turn on the Pan Behind tool, turn on snapping, so when I drag it, it'll move up right there. And then all I'm going to do is build a quick, like, little one-second animation for this.
So I'll go to my Properties panel, Rotation. I'm just going to rotate it from, like, 30 degrees, like that. I'll turn on the stopwatch.
Over one second, I'm just going to animate that to negative 30, so it swings back and forth. So it'll swing back and forth. That's the goal I'm looking for.
I can do it down here. It doesn't really matter. You can do different numbers.
It's just, this is, like, what I wanted. And of course, it stops. What I want to do is for it to keep going.
Now, I could copy and paste a bunch of keyframes, but that would take a while. And the problem with copy and pasting keyframes is that the more keyframes you have to manage, the more trouble it is when you want to adjust, like, the duration or length or pacing of your animation. So I can keep as few keyframes as possible.
This is a script to keep them moving. That saves me time and is easier to modify later. So let's do that.
To add an expression, I'll hold down the Option key on my keyboard, the Alt key if you're a Windows user, and click on the stopwatch. You can also add an expression when the property is highlighted by going to the Animation menu, Add Expression. So either Option or Alt, click on the stopwatch, or this command.
There's also a keyboard shortcut that I never remember. It's that. So have fun.
I like this Option-Alt. That'll give me the expression text field right below my keyframes. It opens up the expression row, and the numbers turn red.
That's how you know there's an expression here. So I'm just going to replace this text with loop out. Okay, and as I start to type it out, it's gonna start hinting on this list.
I can use my up and down arrow keys to go up and down the list, and when I highlight what I want, I can either double click on it or just press the Return or Enter key on your keyboard to finalize it. Using the code hint, which is the list of codes, and the code completion, the fact that I'll write it out for you, is basically going to guarantee you don't make typos. The most common errors, by the way, in code are usually typos.
I'll go to the end of the line and add a semicolon. Semicolon isn't really necessary in this case because it's only one command we're ever using, but if I was going to add multiple lines of commands, it would become useful. So it's just a good habit to get into.
It's like a period of a sentence. It tells the After Effects program that this command is finished. I'll leave the field as click outside of it, and now I have looping animation.
But that's what it does. It simply repeats the keyframes over and over again, which means it gives that really weird jump back to the beginning. So I'm going to modify that.
Stop my preview, click right inside of the parentheses, and in quotes, I'm going to add what's called an argument. It basically tells this function, which is what loopout is, a function is a command, what to do or how to behave. By default, it's just cycling.
A, B, A, B, A, B. But what I want to do, in quotes, it'll give me another hint. I'll find ping pong and use that. Again, I will click outside of the text field to finalize the expression, and now what I get is that.
It swings back and forth. It ping pongs back and forth like a ball being hit across the ping pong table. That is the ping pong type of the loopout.
I'll stop that preview. Now that's good. It's not always going to work in all situations, but it's pretty good.
Okay, now I'm going to add some animation to the minute hand and the hour hand, and I admit I'm going to basically adjust their anchor points first. It's just easier to do it at once, and then I'll come back and animate each of them separately. I'm going to animate the minute hand first, right there, and again, its rotation from the beginning is going to be rotation zero rotations, zero degrees.
That's the first keyframe, and at one second, I'm just going to press K on my keyboard to jump to that keyframe right there I can see for rotation in the pendulum. It's going to be 1x, one full rotation. So the first number is the number of full rotations to make, so the program just looks at the two keyframes and sees how this number is different and rotates that total number of times.
The second one is the degree value, so if you're rotating less than a full rotation, you only use the degree value. If you are rotating two, three, four times totally, you use the number before the X. So I'll get one for rotation on that, and again, it stops, so I'm going to add my expression. This time I'll highlight it and use the command, animation, add expression.
I'm going to pause the preview until I'm finished with the expression. Sometimes it does that, sometimes it doesn't. So in this case, it did.
I'll add loop out again. Again, I type loop, L-O-O-P, and then I'm going to use the completion there so I don't mess up the spelling, and the capitalization matters. This time, I don't do anything inside the parentheses.
It's going to do its default behavior, which is the cycle, so I'll leave the field, and now I have that. It simply cycles, repeats over and over again, A-B, A-B. That's good when you have something that ends or starts off screen, and it's good in this case where something makes one full rotation or it starts and stops at the same exact value.
One more, and then I'll be done with the loop for this, the hour hand. The hour hand rotates 30 degrees. Stopwatch for rotation on.
I'll press K to jump to the next keyframe, the one at one second, or I could just go to one second exactly, and it's going to rotate 30 degrees every time the minute hand makes one full rotation, and then of course it'll stop. So I'm going to add a loop to this one, loop out, not loop in, loop out. Loop out loops after the last keyframe, and in parentheses, I'm going to tell it offset.
So what offset does is that every time it loops, it increases the value. So zero to 30 degrees is the first set of keyframes, which means in the next one second, it'll go to 60 degrees, next second after that, it'll go to 90 degrees, and so on and so forth. So it just keeps incrementing up the value.
It just keeps repeating. I'll leave the field. I'm going to fit in window.
I'll use the magnification, fit up to, and now what I should have is a clock animation like so, and each of them is made with two simple keyframes. So why is making it with fewer keyframes better? Here's one of the reasons. I'm going to slide down to that pendulum animation.
I'm going to highlight those two keyframes by clicking on the name of the property rotation, and I'm going to easy ease them. Keyframe assistant, easy ease. It just updates.
It's all based on the exact same set of two keyframes. So now that easing, that movement looks a lot more realistic. If I had had to copy and paste keyframes to do that, I would have had to do that to 10, 20, 30, 50 keyframes maybe.
A lot less trouble. Okay, I'm going to press U on my keyboard to show only the animatable properties like so, and what I want to do now, I'm going to hide everything. I'm going to stop my preview.
I'm going to highlight all my layers. That was command A or control A. I'm going to hide all my properties. That's command tilde or control tilde.
Tilde is the squiggly line above tap. This time it expanded them all. I'll do it now to hide them all.
Okay, now if I press U, it'll only show me these three animated properties. What I want to do is grab all of the ending keyframes, and instead of a one second animation, what if I decide to go to a two second animation? So I'll drag all the three of these over. I'm going to hold down shift while I snap.
And again, because this is all created by a loop, no problem at all. So I've slowed down the animation, made it slow in half, only by moving three keyframes rather than adjusting the timing of possibly 30, 40, 50. So it's a lot more efficient to use loop out when you have repeating animation.
Now keep in mind, loop out isn't designed to stop. There are ways of stopping expressions like loop out at a certain time or a certain range, but that requires usually writing a bit more code. So in this case, my goal was to create something that would run forever, and that's the way I'll be using most expressions.
I want something that runs forever, something that randomizes forever. If I need to stop it usually, or if I need to stop it at specific points in time and have things happen and have things timed to like voiceover or music or something, I'll use keyframes for that. But for repetitive repeating animation, expressions can be very, very helpful.
And if you do decide to explore it, it is a very powerful language, and there are people who specialize in this aspect of After Effects. So that looks pretty good. And that's how you use the loop out expression.
Now technically, by the way, there was a fourth word that I could have put in the parentheses. It's called continue. Continue is the fourth argument that I could actually put inside of the parentheses.
It would have actually, in this case, done pretty much the same thing that cycle did where I would have used it on the minute hand, if anywhere. It might have even done the same thing that I did with offset as well. It basically just calculates the change in value, just keeps going.
So apparently it's not a loop, but they just list it with loop out. But these are the three common variations of the loop out expression.