After Effects Tip: Auto Fit To Comp Size Expression

Auto Fit to Comp Size Expressions is what this tip is all about. So let’s dive right in!

Auto Fit To Comp Size with a Shape Layer

Alright so here we are in After Effects and for this example, I have an image of my kids.

Image of Kids

and this shape layer right here.

Shape Layer in Adobe After Effects

By the way, this shape layer is an adjustment layer and has some effects applied to it.

Adjustment layer with effects in After Effects

If I turn off the Adjustment Layer, you can see what it looked like before.

Turn off adjustment layer in After Effects

I want to rig this shape layer to where it always stays the exact same size as my composition. For example, if I press CTRL+K on a PC or CMD+K on a Mac

Composition Settings in After Effects

and try to change the size of my composition just slightly like this

Changing the composition settings in After Effects

You can see that the shape layer is kind of affecting a lot of things here. It is not covering a lot of the new area. It didn’t change in size but my composition has. So how do I rig it up to where it is always the exact same size as my composition?

It doesn’t matter what I change in my Composition Settings, I want the shape layer to remain the same size. So let me show you how to do this.

I’m gonna CTRL-CLICK on this triangle in our timeline on PC or CMD+CLICK on a Mac.

Click on the triangle in after effects

Then I’m going to select size and press S twice on my keyboard to sole it.

Solo property keyboard shortcut in After Effects

ALT-CLICK on the stopwatch icon to activate the expression

Activate Expression in After Effects

and in the white text box, I’m just going to label my variable

I will type sizeX = thisComp.width;

Expression After Effects

So basically I want for sizeX to be the width of my Comp.

For the next one, I’ll do the same thing for the sizeY, but instead of width, I will say height like so: sizeY = this.Comp.height;

Height in After Effects

Okay, we are almost there!

Next, I’m going to define them in the square brackets. So I’m going to say: [sizeX, sizeY]

Alright, X is going to be sizeX and y is going to be sizeY.

So now if I let go, you will notice that nothing happens.

Nothing Happens

But let press CTRL+K on a PC or CMD+K on a Mac and open up our Composition Settings.

Composition Settings keyboard shortcut in After Effects
If I increase the size of my composition, you can see that my shape layer is always staying the exact same
size as my composition.

Auto Fit to Comp Size Expression After Effects

Auto Fit To Comp Size with a Solid

So in the last example, we use a shape layer but let me show you how to set up the exact same thing using a solid.

Solid After Effects

So now I have a solid in my composition. It is an adjustment layer and it has the exact same effects as before but how do I make this solid remain the exact same size as my composition? Let me show you!

To do that I’m going to press S on the keyboard to reveal the scale property

Scale Property reveal keyboard shortcut in After Effects

Then ALT+CLICK on the scale stopwatch icon.

Activate Expression on scale After Effects

And inside the white text field, we’re going to type some expression.

sizeX = 100*thisComp.width/thisLayer.width;

sizeX is just a variable. So basically the width of this comp divided by this.Layer.width

Type After Effects Expressions

That is the first expression and the second we’re going to do:

sizeY = 100*thisComp.height/thisLayer.height;

After Effects Expressions in white box
Now I will define them in the square brackets. So in here, I’m going to say the X is going to be sizeX and then the Y is going to be sizeY like so:

[sizeX, sizeY]

X and Y After Effects Expressions

Okay and now if I let go nothing happens just like it was in the last example. Let’s press CTRL+K on a PC or CMD+K on a Mac and bring up our composition settings.

Keyboard Shortcut Composition Settings After Effects

Next, let’s change the size of my composition.

Adjusting Composition Settings in Adobe After Effects

As you can see that it is adjusting to the size of my composition.

Bonus Example:

Now let me show you another useful example you can use. So right now I have this modular lower third kit in our
composition, which by the way, you can purchase it at Ukramedia.com/shop.

Modular Lower Third Kit After Effects Ukramedia

So here’s what I want to do, I want for this a lower third to always have the same size and have the same position as I change the size of my composition.

For example, let’s bring up our Composition Settings with the keyboard shortcut CTRL+K on a PC or CMD+K on a Mac.

Adobe After Effects Composition Settings Keyboard Shortcut
Now let’s change the size of my composition settings. When we do that, you will notice that the lower third will not scale up with the composition.

Lower Third did not change in size

So how do I fix it? Let me show you!

All you have to do is simply parent the modular lower third kit to the adjustment layer.

Parenting to adjustment layer in After Effects

The adjustment layer automatically fits in size so it will basically do the exact same thing to the lower third.

So if I bring up my Composition Settings again with the keyboard shortcut CTRL+K on a PC/CMD+K on a Mac and change the size of my composition, you will see that we are scaling in size but the lower third is staying in the exact same position and size.

Changing the Size of Composition Settings in After Effects

I hope you found this After Effects Tip useful. You can check out all of our Tips on our website. You can learn more about Expressions from my Learn After Effects Expressions Course. Definitely check it out! Also, make sure to subscribe to our email list!

Free Private Facebook Mentoring Group

Lastly, join our FREE Private Facebook Mentoring Group. It is our best FREE online resource. We have thousands of talented motion designers in this group. It is an excellent place to network and grow as a motion designer. See you in the group!

About the author:

Sergei Prokhnevskiy

Sergei Prokhnevskiy is a Charlotte, NC based motion graphics designer, an online tutor, an entrepreneur, and Adobe MAX Master Speaker. Sergei is known for his quick and practical After Effects tips and tricks on YouTube, where he generated well over 6 million views on his tutorials. He has authored an online video course on After Effects Expressions and developed scripts for After Effects. He is also a former senior motion graphics designer at Fox Sports where he worked on graphics for NFL, Super Bowl, MLB, World Series, College Football, NASCAR, Women’s World Cup, and NASCAR Race Hub. He is very passionate about learning and teaching others.

5 FREE TIME-SAVING TOOLS

Over 100,000 downloads & counting!

These 5 After Effects tools will seriously speed up your workflow and save you hours of wasted time. More than that, they could be the difference between being able to complete a project on time or not!