Now let's look at a couple of performance notes with expressions in After Effects
and how to debug errors that may occur in your project.
After Effects evaluates expressions on every property that has an expression,
on every frame of your animation.
The only exceptions are hidden or trimmed layers and deactivated expressions.
If the layer is currently active at the play head and the expression is enabled,
it will evaluate.
This will normally be a non-issue, since expressions evaluate and return a result in milliseconds.
However, you may encounter a situation where multiple expressions are applied
to lots of properties across many layers.
And this is where you may see a rendering or preview slowdown.
Sometimes, complex expressions may bring your render times beyond an acceptable level.
There is a solution, but it's not very pretty.
Select the properties containing expressions on the timeline and go to After Effects
top level menu > Animation > Keyframe Assistant > Expression To Keyframes
This process may temporarily lock After Effects for a few seconds to a few minutes
while it calculates your expressions and converts them to keyframes.
Save your project beforehand.
The longer a compositions duration, the longer this process will take
and the larger your file becomes.
Expressions have no memory.
Expressions cannot pass information about a value from one frame to the next.
This is a rare issue for most expressions but can cause frustrations with complex expression setups.
There are ways to calculate an expression's cumulative value using valueAtTime methods
combined with JavaScript loops.
This process involves calculating the value of every previous frame on every frame,
from the start of the composition.
So naturally, this becomes exponentially longer as the composition time increases
and it's not an efficient solution for rendering.
Now let's take a look at some common errors and how to fix them.
Expression result must be of dimension 2, not 1.
This is one of the most common errors and is very simple to fix.
The problem is caused from a property needing a value of a specific dimension,
but your input does not match.
This is very common on the Scale property when using the Pick Whip tool to link it
to another one dimensional property.
To fix this, you must duplicate the current single value into multiple references
of the value for a property to understand.
Find the line of your expression that outputs the result.
This is usually the last line.
Look at the statement closely.
Is it returning an array?
How many values are in the array?
Once you find this line that outputs the result, you can add a variable to it and create a
dimensional array that references the variable for each index.
Expected close parenthesis.
This is a weird one if you don't know what the error message is talking about.
The error indicates that you've forgotten a parenthesis somewhere in your expression.
This could be caused by either a lack of parenthesis and the end of a statement, or it could be
a syntax error somewhere nearby that creates the illusion of a missing parenthesis.
These errors are especially common around nested mathematical or conditional statements
with parenthesis.
Look through your expression around areas that contain parenthesis.
This could be in if else statements, or around values, or maybe used in conditions.
Try to locate the culprit of the problem by reading through each of these areas and ensuring
that every instance of an open parenthesis is followed with a matching close parenthesis.
Class layer has no property or method named example,
or, property or method named example in class layer is missing.
These errors are caused by a syntax error when referencing an object or an attribute
in your expression.
It's common to run into these when you're trying to link an object to an attribute
that it doesn't have or doesn't exist.
Such as a composition's Opacity, or a layer's value attribute.
Find the line where the error occurs and check the syntax.
Is it following correct object hierarchy?
Make sure the right composition, layer, effect, property, or attribute is paired with the
right object type in your expression.
For example, an effect can't be applied to a composition and a layer cannot have value.
Here's a few general troubleshooting tips for expression errors.
An expression error message will give you a few details to work from.
The property, layer, and comp names will clue you in on surprise errors and where they are.
They're helpful in locating the property but that's about it.
The line in your expression is a very useful way to narrow the problem down
to a specific section of the expression and find exactly where the error is occurring.
The message details will attempt to describe the problem and can sometimes offer
a tiny clue or a reminder to the solution.
Using these three details, you can begin to pick apart your expression, line by line,
and find the areas where your expression is having trouble.
Incorrect syntax is the most common culprit, so checking your code with examples
to make sure your expression matches the same structure is a great place to start.
There are plenty of forums online to help you solve problems if you hit a wall and can't continue.
But it's always faster to try debugging it yourself first before immediately asking for help.
We've arrived at the end of Lesson 406: Performance Notes & Fixing Expression Errors
If you enjoy this expressions course, consider purchasing the paid content.
It includes in-depth documentation, extra tutorial content, high definition videos,
and all the project files used in the training.
Your purchase will help to create more free courses like this in the future.