Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity › Forums › Adobe After Effects Expressions › Use slider expression (in parent) relative to start of subcomp

  • Use slider expression (in parent) relative to start of subcomp

    Posted by Jay Schweg on March 2, 2022 at 11:31 am

    Hi there

    I am trying to reduce duplicated animations and I have a subcomp where I have different elements, that should be hidden or shown depending on a slider input in my parent composition.

    I thought I could just change a slider expression input in my parent comp over time and use different instances of the subcomp to differ the outcome.

    Now the problem is, that my subcomp is taking the slider value always at the given timecode and not the actual value at that time.

    This is a bit hard to understand, so I will make an example:

    I have a parent comp: PARENT which has a CONTROL slider.
    the slider in the parent increases over time:

    0s-5s: CONTROL with value 1
    5s–10s: CONTROL with value 2

    now in my CHILD comp I have an expression where I toggle opacity:

    if (comp(“PARENT”).layer(“CONTROL”).effect(“Slider Control”)(“Slider”) < 2) {
    100
    } else {
    0
    }

    Now I would have expected if I use two instances of my CHILD comp and let them start in two different places, that they would reference the slider value AT the time in the parent comp.
    But unfortunately my CHILD comp is using the slider value at the same timecode, independent of where the CHILD comp is positioned…

    Now with this behaviour I think I can’t have a slider controlling how my CHILD instance looks like, which is a bit of a bummer…

    Or do you have an idea how to either let the CHILD comp reference the value at the correct timecode or how to use a controlling mechanism like this in general?

    Cheers and thanks a lot in advance
    J

    Edit: Sorry creative cow has had problems ulploading my screenshot so I accidentally posted twice.. 🙁

    Jay Schweg replied 4 years, 6 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    March 2, 2022 at 5:18 pm

    I think you actually have two separate problems. One is that if you have an expression in a sub comp referencing an animated control in a outer comp and the sub comp layer in the outer comp doesn’t start at time = 0, your expression needs to compensate for that offset start time. So your example would look like this:

    C = comp("Parent");

    ctrl = C.layer("CONTROL").effect("Slider Control")("Slider");

    L = C.layer(thisComp.name);

    ctrl.valueAtTime(time + L.startTime) < 2 ? 100 : 0

    However, if you are duplicating the sub comp layer in the outer comp, that technique will only work for the top-most layer. To get it to work for any duplicates, you’d have to duplicate the sub comp in the project bin and make sure it has its own comp name. It has to do with how precomps work–if you just duplicate a precomp layer, the duplicate layer still references the same precomp and it only renders once, so it can’t render differently in different layer instances.

  • Jay Schweg

    March 2, 2022 at 5:38 pm

    Well that I am referencing a slider in the outer comp is wanted and should not be a problem. I totally agree about the second problem…

    I thought about the valueAtTime option, but could not find anything that works. But I think the startTime could be the missing link :).

    I will try and get back here. Thanks for your input.

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