4: After Effects Expressions For Beginners: Build a Simple Control Rig

So far, every number in our after effects expressions has lived inside the code. Want a stronger wiggle? Click into the expression, find the number, change it, click out. Fine once. Annoying the tenth time. Unworkable when someone else has to make the change.

Expression Controls fix that. They're effects that don't do anything visible on their own. They just give you a slider, checkbox, color picker or dropdown in the Effect Controls panel that your expressions can read. Change the control, and every linked property updates. Keyframe the control, and every linked property animates with it.

Why your After Effects expressions need controls

Three reasons why these are the bread and butter of a multiexpression setup:

  • One control, many properties. A single slider can drive the spacing of 20 layers.

  • No code editing for changes. You (or a client, or future you) adjust a value in Effect Controls instead of hunting for a number inside an expression.

  • They're keyframeable. Animate the control, and everything connected to it animates.

The Expression Controls lineup

You'll find them under Effect > Expression Controls or in the Effects & Presets panel. Each one hands your expression a different kind of value:

  • Slider Control: a single number. You'll use this one most.

  • Angle Control: a value in degrees, with a dial. Good for rotation or direction.

  • Checkbox Control: on or off, which arrives in your expression as 1 or 0.

  • Color Control: a color picker. Returns four values (red, green, blue, alpha) between 0 and 1, not 0 to 255.

  • Dropdown Menu Control: a list of named options. Returns the position of the selected item, starting at 1.

  • Layer Control: a layer picker, so an expression can use "whichever layer is chosen here" instead of a hardcoded name.

  • Point Control: an X/Y coordinate for positions, anchor points or effect centers.

  • 3D Point Control: X/Y/Z, for 3D position and orientation.

Set up a controller null

You can apply Expression Controls to any layer, but I'd put them on a null and nothing else. That keeps all the controls in one predictable place, away from layers that might get deleted, replaced or precomposed.

  1. Choose Layer > New > Null Object and rename it to something obvious. I use CONTROLS.

  2. Apply the controls you need from Effects & Presets > Expression Controls.

  3. Rename each control immediately. Select it in the Timeline or Effect Controls panel and press Enter (Windows) or Return (macOS). "Slider Control 3" means nothing two weeks from now. "Bar Spacing" does.

  4. Pick whip your target properties to the controls.

Rename before you link. After Effects usually updates references when you rename things later, but "usually" is doing a lot of work in that sentence.

Example 1: one slider, many layers

Adobe's own example is a good starting point. Add a Slider Control to a null called "Null 1" and put this on the Position of several layers:

position + [0, 10 * (index - 1) * thisComp.layer("Null 1").effect("Slider Control")("Slider")]

index is the layer's number in the Timeline stack. Layer 1 doesn't move, layer 2 moves by 10 × the slider value, layer 3 by 20 ×, and so on. Drag the slider and the stack fans out. Keyframe it and the fan animates.

Here's the same idea the way I'd actually write it: renamed null and control, a variable for readability, and the slider value used directly as the spacing:

spacing = thisComp.layer("CONTROLS").effect("Bar Spacing")("Slider").value;
value + [0, (index - 1) * spacing]

This index-based pattern is the backbone of most chart templates. One expression, pasted onto every bar, and the layer order does the rest.

Example 2: a checkbox that shows or hides a layer

On the Opacity of a logo layer:

thisComp.layer("CONTROLS").effect("Show Logo")("Checkbox").value == 1 ? 100 : 0

Checked: 100%. Unchecked: 0%. The ? : is JavaScript shorthand for if/else. Read it as "if this is true, then 100, otherwise 0."

Example 3: a dropdown for color themes

Add a Dropdown Menu Control, click Edit next to the Menu property, and enter your options, for example "Red", "Blue" and "White". Then on a shape layer's Fill Color:

m = thisComp.layer("CONTROLS").effect("Theme")("Menu").value;
m == 1 ? [1, 0.2, 0.2, 1] : m == 2 ? [0.2, 0.4, 1, 1] : [1, 1, 1, 1]

Remember: the dropdown returns a number, not the label. Option one is 1, option two is 2. And colors are four values between 0 and 1.

For anything beyond a quick rig, I'd rather keep the actual colors in Color Controls and let the dropdown only choose between them. That way the color values sit somewhere a person can see and change them, instead of hiding in an array inside an expression.

Slider ranges are suggestions, not limits

Sliders show a range you can drag within. To change it, right-click (Windows) or Control-click (macOS) the underlined value and choose Edit Value.

What people miss: that range only limits dragging. Anyone can still type a value outside it. If your rig falls apart at negative values, don't rely on the slider. Clamp the value in the expression:

spacing = clamp(thisComp.layer("CONTROLS").effect("Bar Spacing")("Slider").value, 0, 200);
value + [0, (index - 1) * spacing]

Where this meets MOGRTs

This is exactly how Motion Graphics Templates work under the hood. Drag a Slider, Checkbox, Color or Dropdown control into the Essential Graphics panel and it becomes an editable control in Premiere Pro. The editor never sees an expression. They see "Bar Spacing" and a slider.

That's also why renaming matters so much. The name you give a control in After Effects is often the label someone in Premiere will be looking at. Adobe has a separate help page on building dropdown menus for templates if you want to take it further.

Convert Expression to Keyframes

Sometimes you want to bake the result. Maybe a heavy expression slows down your renders. Maybe you want to freeze a wiggle and hand-fix one frame. Maybe you're handing the project to someone who'll "just adjust the timing a little", and you'd rather they touch keyframes than code.

Select the property and choose Animation > Keyframe Assistant > Convert Expression to Keyframes. After Effects evaluates the expression, sets a keyframe on every frame, and switches the expression off without deleting it. To go back, delete the keyframes and turn the expression on again with the = switch.

Fair warning: a keyframe on every single frame is not something you'll enjoy editing by hand. It's a bake, not a conversion into clean animation.

Up next

Part 5 covers troubleshooting: the warning banner, what the errors actually mean, and why a template that works perfectly on your machine can break in a different language version of After Effects.

Next
Next

3: After Effects Expressions For Beginners: Linking Properties with the Pick Whip