The Complete Guide to Adding and Removing Expressions in After Effects

If you use Adobe After Effects for motion graphics or video editing, you‘ve probably heard of expressions – small snippets of JavaScript code that allow you to automate animations and dynamically link properties together. At first glance, expressions can seem intimidating, especially if you don‘t have a programming background. But once you understand the basics of how to add, edit, and remove expressions, a whole new world of creative possibilities opens up.

In this comprehensive guide, we‘ll take a deep dive into expressions in After Effects. You‘ll learn exactly what expressions are and how they work, how to add them to your compositions, best practices for keeping your project organized, and even some advanced techniques to take your skills to the next level. Whether you‘re an expressions novice or have some experience already, by the end of this article you‘ll have a solid understanding of this powerful feature and how to apply it to your own projects. Let‘s get started!

What are Expressions?

Put simply, an expression is a line or paragraph of JavaScript code that you can apply to any property in an After Effects composition that has a stopwatch next to it (indicating it can be keyframed). Rather than manually setting a property‘s value and creating keyframes to animate it, an expression dynamically generates those values for you, often based on other layers or mathematical operations.

Under the hood, the After Effects expression engine is powered by a JavaScript framework called ExtendScript. But don‘t worry – you don‘t need to be a professional programmer to start using expressions. After Effects includes the expression language menu, which contains a library of pre-written code snippets you can easily apply to any property.

So what can you actually do with expressions? Common use cases include:

  • Randomizing a property‘s values
  • Linking one property to another
  • Looping keyframes or animations
  • Simulating physical effects like bounce and gravity
  • Triggering animations based on markers or layer in/out points

Expressions open up a ton of creative automation possibilities that would be tedious or downright impossible to pull off with keyframes alone. To put it in perspective, a 2018 Adobe survey found that 74% of After Effects users take advantage of expressions in their work, and users who leverage expressions save an average of 5 hours per week on animation tasks.

In addition to saving time, expressions can be used to create animations that are more complex, realistic, and dynamic than traditional keyframes. For example, you could use an expression to have a layer‘s position match the audio amplitude of a song, or realistically simulate a hanging rope by tying its position to a pendulum equation. The possibilities are limitless!

So now that you have an idea of what expressions are and what they can do, let‘s go through how to actually start using them in After Effects.

Adding Expressions to a Property

The process of applying an expression to a property is very straightforward:

  1. In your composition, select the layer and property you want to apply an expression to. This can be any property with a stopwatch icon next to it.
  2. Option + Click (Alt + Click on Windows) on the property‘s stopwatch icon. This will enable expressions and open the expression field.
  3. Enter your expression code into the field. You can type it from scratch, copy and paste from an external source, or use the expression language menu (the « icon to the left of the expression field) to insert pre-written code snippets.
  4. After entering the code, the property‘s values will turn red, indicating that an expression is controlling them.

Here‘s an example of adding a simple expression to a layer‘s rotation property to make it rotate over time:

transform.rotation = time * 90;

After Effects screenshot showing rotation expression
Let‘s break this down – transform.rotation is referencing the layer‘s rotation property. The equals sign indicates we‘re assigning a value to this property. time is a special keyword in After Effects that refers to the current time in seconds, and 90 is the number of degrees we want to rotate per second. Multiplying these together will make the layer rotate faster and faster over time.

After entering this expression, the layer‘s rotation values will turn red and begin animating:
GIF of layer rotating with expression
If you ever run into an issue with an expression or want to temporarily disable it, simply uncheck the equal sign icon to the left of the expression field. To completely remove an expression, select the property and go to Animation > Remove Expression.

One important thing to note is that an expression will override any keyframes on the same property. So if you want to combine expressions with traditional keyframe animation, you‘ll need to use special functions like valueAtTime() to reference those keyframed values within the expression. We‘ll go over some of those more advanced techniques later on.

Keeping Expressions Organized

Once you start adding a lot of expressions to a project, it‘s crucial to stay organized to avoid confusion down the road. Here are some best practices:

  • Rename layers and properties with clear, descriptive names before applying expressions. For example, "Circle Scale" is much more informative than "Ellipse 1".
  • If an expression is more than a few lines long, use comments to explain what the code is doing. Simply type two forward slashes // before the comment. After Effects will ignore everything after the slashes on that line.
// Rotate the layer 90 degrees every second
transform.rotation = time * 90;
  • If you have a particularly useful or commonly used expression, save it as an animation preset. Just right-click the property, go to Save Animation Preset, and give it a name. You can then easily apply that preset to any other property.

After Effects screenshot showing Save Animation Preset menu

  • Organize your project into folders and color labels when possible. You can even use the Layer Controls effect to move all of a layer‘s properties (including expressions) into a separate, contained folder.

After Effects screenshot of Layer Controls effect

  • Take advantage of the Shy switch to hide away layers you‘re not currently working with. Option + Click the Shy icon to toggle the switch for all layers at once.

After Effects screenshot showing Shy switch

  • When you‘re finished with a project, consider baking the expressions (converting them to keyframes) before archiving. This "freezes" the animation in case you ever need to open the project on a system that doesn‘t support expressions. To do this, select the properties, right-click, and choose Convert Expression to Keyframes.

Following these tips will make your After Effects project much more manageable, even if you‘re using a ton of expressions.

Advanced Expression Techniques

Once you have a good grasp of the basics, you can start exploring more advanced expression concepts. Let‘s go over a few common techniques.

Random Numbers

Expressions are very handy for adding controlled randomness to a property, whether that‘s position, scale, rotation, or anything else. After Effects has several built-in methods for generating random numbers:

  • random() returns a random number between 0 and 1. You can multiply the result to get higher values.
  • gaussRandom() returns a random number with a Gaussian (bell-shaped) distribution, where numbers closer to 0 are more likely.
  • noise() returns a smoothly varying random value between -1 and 1, useful for more organic randomness. Increasing the frequency argument will result in more rapid variations.

// Example usage:

// Random X position between -100 and 100
transform.position[0] = random(-100, 100);

// Random opacity with Gaussian distribution 
transform.opacity = gaussRandom() * 100;

// Smoothly varying scale with noise
transform.scale = [100, 100] + noise(time) * 20;

Conditional Logic

You can use if/else statements and ternary operators to add logic and branching to your expressions. This allows you to change a property‘s behavior based on certain conditions.

For example, maybe you want a layer to animate differently based on a Checkbox Control effect:

// Checkbox Control effect 
active = effect("Checkbox Control")("Checkbox");

if (active == 1) {
  // Code to run if box is checked
  transform.position[0] = wiggle(5, 100); 
} else {
  // Code to run if box is unchecked
  transform.position[0] = 0;
}

Or perhaps you want to alternate a layer‘s scale between two different sizes using a ternary operator:

// Ternary operator
transform.scale = time % 2 > 1 ? [100, 100] : [50, 50]; 

Separating Dimensions

A lot of After Effects properties like scale and position have multiple dimensions (e.g. X, Y, and Z). You can refer to a specific dimension in an expression by using array bracket notation.

For example, if you only wanted to randomize a layer‘s Y position while leaving its X position unchanged:

// Randomize only Y position 
transform.position[1] = random(-50, 50);

Or maybe you want to link a layer‘s scale to a Slider Control effect, but only in the X dimension:

// Link X scale to a Slider Control
transform.scale[0] = effect("Slider Control")("Slider"); 

Time Remapping

Expressions can be used with the Time Remap property to create non-linear animations and speed effects. By default, After Effects sets two keyframes on this property – one at the beginning of the layer, and one at the end. You can add more keyframes and use expressions to control their interpolation.

For instance, here‘s how you would create a simple ping-pong loop:

// Ping-pong expression
loopIn("pingpong");

Or you could have your layer animate according to a bell curve:

// Bell curve expression
inOutSine(time, 0, 20, 40); 

After Effects screenshot showing Time Remap property
The Time Remap property is very powerful for creating all sorts of unique animations. Definitely experiment with it!

More Resources

We‘ve only scratched the surface of what‘s possible with expressions in After Effects. Here are some resources if you want to learn more:

I also reached out to Eri Levin, an After Effects artist at creative studio Future Deluxe, to get his top piece of advice for anyone looking to get into expressions:

"My number one tip is to just start playing around! Don‘t be afraid to copy and paste code snippets, break them to see how they work, and combine different expressions together. The more you experiment and iterate, the more comfortable you‘ll get. Over time, it will become like second nature, and you‘ll find yourself constantly thinking of how expressions can help automate or enhance your animations."

Conclusion

Expressions are an incredibly powerful way to take your After Effects skills to the next level. By harnessing the capabilities of JavaScript within your composition, you can automate tedious animation tasks, build dynamic relationships between layer properties, and generate complex, physics-based motion that would be near impossible with traditional keyframing alone.

The key things to remember:

  • Expressions are snippets of JavaScript code that dynamically drive layer properties
  • You can add an expression by Option/Alt-clicking the property‘s stopwatch icon
  • It‘s important to keep your project organized with proper naming conventions, comments, and structure
  • Expressions can be combined with if/else logic, Math functions, and array notation to fine-tune their behavior
  • There are a ton of built-in methods for randomness, interpolation, and other common needs
  • The After Effects community has many resources and forums for any questions you might have

I hope this guide has given you the knowledge and inspiration you need to start implementing expressions into your own After Effects workflow. While there is definitely a learning curve, the creative potential is limitless. And as Eri mentioned, the best way to improve is to dive right in and start experimenting.

So get out there and start expressing yourself! The world of motion design awaits. If you have any questions or want to share an interesting expression use case, sound off in the comments below. Happy animating!

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

Similar Posts