Skip to main content
Participating Frequently
April 8, 2022
Question

Time discrepencies with expressions in nested comps

  • April 8, 2022
  • 3 replies
  • 3388 views

This is a tricky one. I'll try and explain!

I have an animation of a fly buzzing, the fly floats around via a wiggle expression that gets it's amplitude value from a slider in the parent comp. Easy so far. The issue is the slider's keyframe and the fly's corresponding animation only line up if the fly comp starts at 0 on the main timeline. If it starts at say, 2 seconds in, then whatever the key frame on the slider is, the fly comp isn't effected until 2 seconds later. I'll include a graphic to clarify. So I'm trying to write an expression that looks at where on the timeline the fly comp starts, and then offsets it's value from the slide by that amount of time. It's not working lol. Below is the code AND the diagram (I'm trying to create the bottom instance). Help!

This topic has been closed for replies.

3 replies

Participating Frequently
April 12, 2022

Ok, first off - thank you all for your help. I have one last shot at this. I simplified the comps so that it was just a null with 2 sliders to control the fly floating and it's wings flapping. Fly Comp (parent, with the expression on it's position property because I wasn't sure where else to put it) -> body of fly (layer 1), wings of fly (layers 2 & 3). Here's the expression with comments describing my intention and what's not working. If I can't get somewhere with this I'll have to make a bunch of different fly comps etc and do it the dirty way. I've also included a screen of the expression if that's easier to read.

 

// this is the control null layer with sliders -  always the null layer above a layer called 'Fly-1'. 'Fly-1' contains to layers which I later access by their index (1 &2)
var controlLayer = thisComp.layer(thisLayer.index-1); 

// first slider on the null, intended to add position wiggle amp value to a comp INSIDE of this comp (remember this comp is 'fly-1')
var pAmp = controlLayer.effect("shake").slider.value;

// second slider on the null, intended to add rotation wiggle amp value to a comp INSIDE of this comp (remember this comp is 'fly-1')
var rAmp = controlLayer.effect("flap").slider.value;

// the layers I want to access INSIDE this comp ('fly-1') - when checked with a throw Error, this returns the correct layers inside this comp 
var theFly = source.layer(1)
var theWings = source.layer(2)

// problem: theFly is being wiggled, instead of layer 1, inside the fly
theFly.position.wiggle(2,pAmp)
// problem: theWings line throws a 'expression must be of dimension 3, not 1' error and causes the entire thing to fail
theWings.transform.zRotation.wiggle(40,rAmp)

 

Inspiring
April 8, 2022

Layer.sourceTime(t) will get you the time in the layer's source (here the nested comp) that corresponds to time t in the comp in which the expression is evaluated. This will be more reliable than doing the math yourself, since it will also account for time remapping, time stretch, reverse, etc.

 

Edit: I might have misunderstood how you have these comps nested. Are you trying to reference the time of the slider from an expression inside a comp nested in the same comp that the slider is in? If that is the case, my solution wouldn't help, since it is for the reverse situation, where you are trying to reference properties inside a nested comp in an expression that is in the containing comp.

Participating Frequently
April 8, 2022

So the slider is on the main timeline, and it's controlling an expression inside another comp on that timeline (that would be the nested comp). 

Inspiring
April 9, 2022

Offsetting the time based on the start time is the simplest way to go for this application, I think.

 

This seems to do the trick:

 

var mainComp = comp("_VIRGIN-PLUS-MOCK-ENG");
var controlLayer = mainComp.layer("shakeControl 1");
var nestedLayer = mainComp.layer(thisComp.name);
var amp = controlLayer.effect("Slider Control").slider.valueAtTime(time + nestedLayer.startTime);
wiggle(2, amp)

 

This won't account for time stretch or reverse. It would be possible to do those with some interpolation, but time remap would be off the table due to its ability to map the same source time value to multiple different comp time values.

Mylenium
Brainiac
April 8, 2022

As easy as accounting for the layer inPoint() in your time calculation and subtracting that value...

 

Mylenium

Participating Frequently
April 8, 2022

Ok - I'm punching above my weight class on all this stuff - how would I write it then?