Skip to main content
iamjustoneman
Known Participant
February 16, 2023
Question

Possible to Keyframe an Expression?

  • February 16, 2023
  • 3 replies
  • 777 views

Hi all, 

 

I am basically trying to work a bit smarter within AE, as a result, I have created effects that the brand colours used throughout my project. Then on the main timeline, I have a background shape that uses an expression to pull in one of the Brand colours from the colour effect, my expression looks like this:

thisComp.layer("Control Panel").effect("BG Colour")(1)

 

This works great, what I would like to do though is at different stages of the timeline, change the expression to use another saved colour, so essentially, change the expression to this:

thisComp.layer("Control Panel").effect("BG Colour 2")(1)

 

I could just duplicate the background shape layer and change the expression, though figured I would check if multiple expressions can be added at different points of the timeline, essentially, the ability to create keyframes for expressions?

 

Any help appreciated.

 

Thanks

This topic has been closed for replies.

3 replies

Dan Ebberts
Community Expert
Community Expert
February 16, 2023

The simplest might be an expression that uses the first color if there are no keyframes or the current time is less than the time of the first keyframe, otherwise it uses the second color:

if (numKeys == 0 || time < key(1).time)
  thisComp.layer("Control Panel").effect("BG Colour")(1)
else
  thisComp.layer("Control Panel").effect("BG Colour 2")(1)

 

iamjustoneman
Known Participant
February 16, 2023

That looks neat, thanks.

Inspiring
February 16, 2023

Are you trying to fade from one color to the next or are you ok with a simple swap?

If the latter, you can do this in a neat way. I like to use an the Dropdown Menu Expression Control with a switch statement.

Here's an example .aep for both AE 2022 and 20223 with some comments in the expression. 

You can add as many color swatches on the Controller layer as you want, then you can add more items to the Dropdown Menu controller and update the expression.

iamjustoneman
Known Participant
February 16, 2023

Brilliant, will give that a try.

Community Expert
February 16, 2023

You can add an Expression Control Menu or checkbox and then include an if statement. Then all you have to do is keyframe the controller. It's basically if (Checkbox == 1) color is color 1, else color is color 2. I build this kind of thing all the time using the Extended Graphics Panel and a bunch of color samples.