Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions valueAtTime() not working in nested comp

  • valueAtTime() not working in nested comp

    Posted by Joel Daniels on September 18, 2023 at 2:20 pm

    Hi all, I know similar questions have been asked before, but the answers don’t seem to explain the problem I’m having.

    I’ve got a comp (for clarity, we’ll call it “Precomp”) nested within a master comp (we’ll call it “Comp”). Within Precomp, I’ve got a DUIK Effector; in Comp, I’ve got a mouse cursor shape layer. I want the Effector in Precomp to follow the mouse cursor in the parent comp. Easy enough. But the Precomp layer within Comp starts at the 2 second mark. I’m trying to use valueAtTime() to get the time-offset anchor point of the mouse cursor, but it’s simply not giving me the time-offset value; it’s only giving me the value at the current time in the precomp. I can’t figure out what I’m doing wrong. Here’s what I have on the position property of the Effector inside of Precomp:

    compMaster = comp(“Comp”);
    mouseLayer = compMaster.layer(“Mouse Cursor”);
    precomp = compMaster.layer(“Precomp”);
    layerStart = precomp.startTime;
    anchor = mouseLayer.transform.anchorPoint.valueAtTime(time + layerStart);
    mouseLayer.toComp(anchor)

    What am I missing?
    Edit: Just to say that if I make a text layer and add an expression to its Source Text to tell me the value of “layerStart + time”, it does give me the accurate current time of the master comp. Passing that correct value to valueAtTime() just seems not to have any effect.

    Brie Clayton replied 1 week, 4 days ago 3 Members · 3 Replies
  • 3 Replies
  • Filip Vandueren

    September 19, 2023 at 8:27 am

    Hi Joel,

    I’m suspecting that it’s not really the anchorPoint that is being animated, but you’re just using the anchorpoint for that toComp() method.

    You should also include the time with the toComp method like this:

    compMaster = comp("Comp");
    mouseLayer = compMaster.layer("Mouse Cursor");
    precomp = compMaster.layer("Precomp");
    layerStart = precomp.startTime;
    anchor = mouseLayer.transform.anchorPoint.valueAtTime(time + layerStart);
    mouseLayer.toComp(anchor, time + layerStart);

    Caveat that this code supposes that only that startTime has changed, so the speed of the preComp layer (stretch or timeremapping) must be at 100% or the code won’t work.

  • Joel Daniels

    September 19, 2023 at 11:47 am

    Ahhhh, thank you so much. I wasn’t aware that toComp() took another argument! That’s the ticket, it works perfectly.

  • Brie Clayton

    September 19, 2023 at 4:02 pm

    Thank you for solving this, Filip!

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