Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Slider expression not working when keyframes added

  • Slider expression not working when keyframes added

    Posted by Del Agnew on September 20, 2018 at 4:46 pm

    Hi guys!

    Long time lurker, first time poster. Apologies in advance if this has been covered elsewhere (I’ve scoured other threads but haven’t found a solution)

    I have a Slider expression that is set up to control the opacities of 3 layers. The Slider Value Scale is set between 0 – 100.

    Basically the expression states that if the value of Slider A is between a certain range then the opacity for that given Layer is 100 else 0.
    So let’s the call them “Layer A” “Layer B” “Layer C”

    The expressions for each are:

    “Layer A” : if(comp(“Comp A”).layer(“Layer 1”).effect(“Slider A”)(“Slider’)<=25)100 else 0

    “Layer B” : if(comp(“Comp A”).layer(“Layer 1”).effect(“Slider A”)(“Slider’)>=26 && comp(“Comp A”).layer(“Layer 1”).effect(“Slider A”)(“Slider’)<=50))100 else 0

    “Layer C” : if(comp(“Comp A”).layer(“Layer 1”).effect(“Slider A”)(“Slider’)>=51 && comp(“Comp A”).layer(“Layer 1”).effect(“Slider A”)(“Slider’)<=75)100 else 0

    The expressions themselves check out. When I adjust the value of the Slider scale the layers’ opacities adjust accordingly. However as soon as I try to keyframe the slider values, the expression freezes to whatever the first keyframe value is. So basically if “Layer B” is visible when I start key-framing, only “Layer B”. will be visible from that point forward, no matter the change in Slider value.

    I hope I’ve explained this thoroughly enough. I’m very confused as to why the keyframes would be the issue. I thought initially that I might have too many compositions and too many expressions, however I stumbled across a thread where someone said they have “600 comps and 8000 expressions” and everything works fine.

    Is there some setting that I’m missing here? It’s only been a problem within this composition.

    Any help would be much appreciated. Thanks in advance!

    -Del

    "Layer A" : if(comp("Comp A").layer("Layer 1").effect("Slider A")("Slider')&lt;=25)100 else 0

    "Layer B" : if(comp("Comp A").layer("Layer 1").effect("Slider A")("Slider')>=26 && comp("Comp A").layer("Layer 1").effect("Slider A")("Slider')&lt;=50))100 else 0

    "Layer C" : if(comp("Comp A").layer("Layer 1").effect("Slider A")("Slider')>=51 && comp("Comp A").layer("Layer 1").effect("Slider A")("Slider')&lt;=75)100 else 0

    Dan Ebberts replied 2 years, 11 months ago 5 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    September 20, 2018 at 6:02 pm

    This will happen when you’re referencing a keyframed in (or from) a precomp and the precomp doesn’t start at time zero in the main comp. You have to compensate for that offset in your expression by using valueAtTime() with an offset equal to the start time of the precomp layer in the main comp. The exact code depends on how you have things set up.

    Dan

  • Kalleheikki Kannisto

    September 20, 2018 at 6:21 pm

    All three lines had typos in them that had to be fixed before this worked at all. Single quotes and missing parenthesis. Once fixed, I had no problem keyframing them.

    Layer A
    if(comp("Comp A").layer("Layer 1").effect("Slider A")("Slider")<=25)100 else 0
    Layer B
    if(comp("Comp A").layer("Layer 1").effect("Slider A")("Slider")>=26 && comp("Comp A").layer("Layer 1").effect("Slider A")("Slider")<=50)100 else 0
    Layer C
    if(comp("Comp A").layer("Layer 1").effect("Slider A")("Slider")>=51 && comp("Comp A").layer("Layer 1").effect("Slider A")("Slider")<=75)100 else 0

    Or, if that doesn’t do it, what Dan said.

    Kalleheikki Kannisto
    Senior Graphic Designer

  • Jp Pelc

    October 21, 2020 at 10:36 pm

    Dan, once again you are a frickin’ genius. Thank you so much

  • Isheau Wong

    June 8, 2023 at 9:18 pm

    Hi Dan,

    I’m experiencing the same kind of problem. I made a full rig of a character with head turns in 5 different positions. The slider control is used for the blink. The way I have my rig set up is:
    Eye Comp: 5 positions (side, 3/4, front, 3/4, side), with 3 layers each: open, half closed, closed
    Eye pose comp: contains three layers (three of the eye comp), in which I wrote an expression for the slider: if (s = 0) {100} else {0}, and so on for s = 1 and s = 2.
    Eye pose comp is in the head comp, where head is linked to head control slider.
    Head comp is in the main rig
    rig is imported into main comp
    so with this set up the slider works perfectly until I keyframe the slider control in the rig comp. How would I proceed to fix this problem?
    Thank you so much!

  • Dan Ebberts

    June 8, 2023 at 9:57 pm

    It could be complicated, if you have to compensate for every level of comp nesting. However, I’m guessing that going up the heirarchy, there aren’t many instances where the nested comp layer doesn’t start at time = 0 in its parent comp. If you can identify those situations, it will simplify the code.

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