Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Expression for switching between layer opacities

  • Expression for switching between layer opacities

    Posted by Scott Hewitt on June 5, 2014 at 12:14 am

    Howdy everyone!

    I’ve tried searching for a solution to this, but it’s kind of a specific questions.

    I have created a character with multiple angles (Front/LEFT/RIGHT. I have rigged it so that when I make the character walk with a master controller all angles follow. However, to streamline switching between angles, I was wondering if there is an expression I can add to a slider on the master control that will switch the opacity of the layers?

    If any one knows how to do this, I’d love to hear!

    Thanks, I hope whatever you may be working on is rockin’!

    Scott

    Filip Vandueren replied 12 years, 3 months ago 2 Members · 3 Replies
  • 3 Replies
  • Filip Vandueren

    June 7, 2014 at 7:06 pm

    Copy this expression to your three layers.
    Change the value for myIndex to what you want to respond it to. 1/2/3 I guess ?

    Make sure you change “Null 1” to the name of your controller Null and add an Expression control:
    Slider that you rename to “switch”

    I’ve added a rounding so for example 1.4 will still trigger 1.

    myIndex = 1;
    e=Math.round(thisComp.layer("Null 1").effect("switch")("Slider").value);

    e==myIndex ? value : 0;

  • Scott Hewitt

    June 9, 2014 at 1:12 am

    Bam! That worked an absolute treat! Thanks Filip!

    If you wouldn’t mind, could you please break down the expression for me? I just want to understand why it’s doing what it is doing…

    Thanks again!

    Scotty

  • Filip Vandueren

    June 9, 2014 at 7:13 am

    I think the first two lines are self explanatory?
    Store the value 1 in a variable my Index
    Store the rounded value of the switch slider in the variable e

    myIndex = 1;
    e=Math.round(thisComp.layer(“Null 1”).effect(“switch”)(“Slider”).value);

    e==myIndex ? value : 0;

    The final line uses ? : which is shorthand for if / then / else:
    If e equals myIndex then value else 0

    This could have been then 100 else 0
    But by using “value” you can still set it to an other opacity or keyframe a fade In etc.
    Value refers to the value of the property before expressions were applied.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy