← Back to blog
|
May 26, 2023

After Effects scripts vs expressions

After Effects scripts and expressions can help you improve your After Effects workflow and your projects. They both utilize JavaScript code in order to automate things within After Effects – so what’s the difference?

What’s the difference?

Expressions are usually a little simpler than scripts. Each expression can only affect a single property within a single layer (i.e. Position).

par = parent.sourceRectAtTime(parent.sourceTime());
nudgeX = par.left + par.width;
nudgeY = par.top + par.height;
[value[0]+nudgeX,value[1]+nudgeY]

Of course, you can have multiple expressions on the same layer, and there is no limit to how many expressions you can add to your project. But expressions cannot create new layers, effects, keyframes, or properties. And they can’t remove or rename anything.

Scripts on the other hand have virtually no limit to what they can control inside After Effects. With scripting, you can create new layers, delete and rename layers, add files, edit any property, manipulate keyframes, and add any effect. Scripts even allow you to add expressions.

After Effects code engine

Expressions use the V8 open source JavaScript engine. You can also use ExtendScript, but I would recommend always using JavaScript (File > Project Settings> Expressions). This isn’t a complete version of JavaScript as many functions are not available. Again, you can’t write to any other properties other than the one that the expression is applied to. You also can’t run alerts – that would get annoying though since it would result in an alert every frame of your animation.

This engine also has some specific After Effects extensions built into it. And you can see a lot of these under the Expression language menu.

Meanwhile, After Effects scripts use an old version of JavaScript – ES3, which came out in 1999. Since this is an outdated version of JavaScript, you don’t have access to many modern features like block-scoped variables, arrow functions, promises, and a bunch of other stuff.

How expressions and scripts are run

Expressions work by running through the block of code once per frame. And then it does the same thing the next frame, the next frame, and so on. But it’s doing this from scratch each time. So you can’t do something like store a variable on one frame and then access that variable in another frame. But luckily you can use extensions like time and valueAtTime to get around these limitations.

Scripts are typically executed one time with a button click. This gives expressions a unique power, because they can react to other parts of your scene without having to reapply anything. On the flip side this also increases the load that expressions can add to a project.

If a script takes a half second to execute, you might not even notice it. And once it does its thing, it typically doesn’t take any extra computing power. But if an expression takes a half second to execute, it would take 12 seconds to play 1 second of a comp – and that’s assuming it’s the only expression.

That being said, I’d recommend utilizing scripts and expressions in your After Effects workflow wherever it makes sense. Even if you have no interest in becoming a developer, learning to write even simple expressions can save you a lot of time down the road. And if you do want to write your own After Effects scripts, I’d still recommend starting with expressions, since this will give you a good understanding of how to manipulate properties in After Effects with code – and you’ll be able to use that knowledge later on once you’re writing After Effects scripts.

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.