← Back to blog
|
February 20, 2022

How to use expressions in After Effects

After Effects expressions can be very useful — but they can also be very intimidating.

If you’ve never used an expression, it might seem like they delve into developer territory. And the truth is, some expressions can be complex, but expressions can also be very simple.

That’s the great thing about expressions! They’re incredibly flexible and there’s an unlimited way you can use them to improve your workflow and set up motion graphic scenes that would otherwise be humanly impossible.

What is an expression?

An expression is a dynamic way to set the value of a property in After Effects with a bit of (simple) code.

For example, you can use expressions to link the scale of each layer in a comp – so everything moves together.

The entire animation above is being controlled with just 3 keyframes thanks to expressions. Without expressions, this would require 24 keyframes!

You can also use math, incorporate built-in After Effects objects, add if statements, and more for more complex expressions.

How to add an expression

To add an expression, toggle to any property that can be key-framed. Hold Option (Mac) / Alt (PC) and click the stopwatch. This will bring up a small text editor to write your expression.

Basic expression syntax

You can do plenty with expressions just using the expression pick-whip and avoid writing code altogether. That being said, it is helpful to recognize understand a tiny bit of JavaScript – the coding language that expressions are based on.

control = thisComp.layer(1).transform.rotation * 2;
control

In the code above, a variable is being declared called, “control.”

This variable is equal to the rotation of the very top layer in the composition multiplied by 2.

The expression then calls the newly created control variable.

The result is a layer that rotates twice as much the other layer.

How to use the expression pick whip

The expression pick whip is the easiest and fastest way to link an expression to any property.

To use, simply click pick whip icon and drag it to any property you want to link. After Effects will automatically inject the necessary code for you!

The pick whip is also great for more complex expressions, since you can use it in any part of your code.

How to add expression controls

Some of the best effects in After Effects do absolutely nothing. At least not until you add expressions. Meet expression controls!

Expression controls are designed to give you an easy way to control variables in your expressions. You can apply these to any layer by selecting Effect > Expression Controls > whatever type of control you want.

Once you have an expression control, you can reference it in any expression using the pick whip method mentioned earlier.

You can even rename these effects to make your projects more organized – perfect for making After Effects templates.

Example expressions

If you want to see some moderately complex expressions you can download Num or Get Rect for free. Both of these presets rely on expressions and expression controls. After using either of these presets, you can see the expressions for yourself by double tapping “e” on your keyboard.

Here are some more expressions you can try for yourself.

Rotate forever

Apply this expression to the rotation of a layer:

time * 180

This will cause the layer to rotate 180 degrees every second. You can adjust the speed by changing the number.

Loop position animation

Apply this expression to the position of a layer with existing position keyframes:

transform.position.loopOut()

This will cause the position animation to repeat over and over.

Count number of layers

Apply this expression to the source text of a text layer:

thisComp.numLayers

This will change the text to display however many layers there are in the current comp.

Start using expressions

The best way to learn After Effects expressions is to start using them!

Once you start adding expressions to your motion graphics workflow, the more comfortable you’ll be creating your own unique After Effects expressions.

If you have any questions about After Effects expressions email help@aescreens.com – we’d love to help you!

Get more After Effects tricks in your inbox.

Check your inbox.

Please confirm your email, so we can keep you in the loop.
Oops! Something went wrong while submitting the form.