How to create global variables in After Effects using a controller layer

Written on 3 February 2014, 09:18pm under Techniques

Tagged with: ,

Expressions are a really powerful feature in After Effects. It can help you improve the quality and fluidity of your animation but it can also help you organize your project. Expressions if used well, gives you the opportunity to create yourself a custom dashboard on which you can control various global variables.

Create a controller

It is a good practice to keep a controller layer in a separate stand-alone composition. You will often see such a thing when you purchase items from marketplaces such as VideoHive.

But even when not selling your source files, you should act as if. Be it for a co-worker taking over your project or just the future you, who won’t enjoy searching through a messy compositions structure.

I usually have a composition named // Controls which contains a // Controller null layer (amongst other things). First off, why the //? That’ll be covered in a future article about naming conventions. Now what’s on this layer? Controls. Indeed.

Remove values from expressions

Say, for example, you have 3 different sequences each containing a camera with a wiggle on their position property. You’ll want to link those wiggle instead of pasting the raw expression in every property. That way you won’t have to make the change to three different places each time you make a modification.

The expression may look a little long but there’s no need to write that by hand.

  1. Select your // Controller layer and click the lock icon in the upper left corner of the effect panel. This will lock our effects panel regardless of our current active composition or layer.
  2. Now add a wiggle expression by using the expression language menu.
  3. Replace every variable with its related slider on the // Controller layer.

More than just sliders

The sliders are good for single numeric values, but every other expression control also has its use.

Check out the expression controls effects to see you available choices. Here are some examples for each of them:

  • 3D Point Control: Controlling lights, cameras, particle emitters or any other 3D objects.
  • Angle Control: Controlling rotation or radial wipes of objects.
  • Checkbox Control: Any boolean (true/false) value. Useful for toggling layers and objects visibility.
  • Color Control: Any color value indeed. This can help you change colors across your whole design and animation really quickly.
  • Layer Control: This one can provide a deeper level of abstraction to your expressions. Instead pointing to a layer as target directly from inside the expression you can point to the the expression’s result as the layer.Consider this example:
    thisComp.layer("Target Layer").transform.position

    Every position property with this expression, will have the same position as the Target Layer. Although if you’d have this expression on 100 different position properties and would decide to follow another layer’s position? You would have to manually reassign the expression to each property.

    Instead, using something like:

    thisComp.layer("// Controller").effect("Layer Control")("Layer").transform.position

    Would give you the opportunity to change the targeted layer later on.

  • Point Control: Anything with an X and Y value. Something’s position maybe?
  • Slider Control: Anything with a single numeric value.

When effects are not enough or how to make reusable expressions

Sometime you will want to directly share the expressions across compositions and layers.

Here’s how you can do it:

  1. Create a text layer in controller composition
  2. Enter your expression as the text layer’s source text value
  3. On every property you’d want to use the expression, use this expression:
eval(comp("// Controller").layer("// Expression").text.sourceText.toString())

This will fetch the text layer’s source text and then parse it as standard javascript.

Having a controller can probably avoid you a lot of headaches by adding a additional layer of abstraction and gathering the different parameters and values of your project. What do you think of this kind of practice, good habit or waste of time?

Other popular articles