I am trying to make a ruler with different length tick marks that I can also animate the distance between the ticks. I set it up so each tick is it’s own layer and the distance between them is controlled by a simple expression on the X Pos and a slider.
It works perfectly, up until I add what seems to be too many ticks. When I add more It glitches in an odd way, where chunks of the ruler move unexpectedly, some disappear from view, and the more I add the more it jumps (almost like a random seed). Originally I thought it was a display error, but the values X Pos values change as well, so something is happening in the calculation.
I restarted, dumped my cache and other the other things I could think of that usually help with glitches. I am running on AE 17.0.6 on a new machine I built so I’m doubting it’s my software or hardware.
I think you’ll get better performance if you avoid a cascading expression (where each expression depends on the result from the expression in the previous layer) and just use a straight ahead calculation based on layer index, like this (not tested):
thisComp.layer(2).transform.xPosition + (index-2)*thisComp.layer(“Control”).effect(“Distance”)(“Slider”)
Try to directly calculate the distance for each tick. Accessing it with index-1 is reaaaly slow because I think AE re-calculates each position to the current one. So, let’s say layer 30, has to calculate 29 other positions so it can add the distance in the end. Try directly multiplying the distance with the number of the current tick. firstiIndex must be the index of your first tick:
firstIndex = 2;
d = thisComp.layer("Control").effect("Distance")("Slider");
value + (index-firstIndex)*d
This worked perfectly thank you so much for your help! Do you mind explaining why this would work better? Is it simply because it’s only having to calculate once as opposed to every single layer? Makes it easier on the processor and thus less likely to have a glitch like mine? I’m trying to learn more about expressions and best practices for them. Thanks again!
That’s pretty much it. They way you had it, the expression in layer n requires the expression engine to recalculate the expression in layer n-1, which requires recalculation of layer n-2, and so on, increasing geometrically with the number of layers. It can bog things down in a hurry.