-
Weird sourceRectAtTime bug… or is it?
Bashing my head against the desk a bit with this one… I have a series of title cards representing categories, named like “TITLE1”, “TITLE2”, etc. Each is 5 seconds long, and between each one is a series of clips. The title cards are between layer 16 and 20, in order – the clips are from about 25 onwards.
I want to have a text layer whose sourceText varies depending on what was the last title card to pop up. So after TITLE1 has been on screen and disappeared again, it should say TITLE1, until TITLE2 appears, after which it says TITLE2, etc. So, this code works on the sourceText:
L = thisComp.layer("CONTROL"); // a "buffer layer" we don't want to go past
doThis = false;
i = 16; // the first "title card" layer
nm = "";
while (doThis == false) {
m = thisComp.layer(i);
n = thisComp.layer(i+1);
if ((m.outPoint <= time) && (n.inPoint >= time)) {
doThis = true;
nm = m.name;
} else {
i+=1;
}
if (i == L.index) { // we've somehow gone too far, or we're at the end
nm = m.name;
break;
}
}
nmBUT – I also want a shape layer as a backing for this text layer, so it stands out on brighter footage. It should resize based on the layer’s changing sourceText and therefore length. This, I think, *should* work on the rectangle size, but it doesn’t.
L = thisComp.layer("Category"); // text layer
b = L.sourceRectAtTime(time, false);
bd = effect("borders")("Point"); // a point layer to add a little border round the text
w = L.position[0] + b.left + b.width + bd[0]*2; // it's left-aligned so this should resize the rectangle based on the rightmost edge of the text layer
h = b.height + bd[1]*2;
[w,h]Expected behaviour: the shape layer’s rectangle element resizes to always fit the text layer.
Actual behaviour: 5 seconds before each new title card comes in, the backing layer resizes to the width of the text layer at the end of the comp – this happens to be the widest title. It’s as if rather than picking up the text layer’s sourceText at the current time, for some reason it’s picking it up from the end of the comp. This is despite the text layer showing the text I’d expect.
In practice I’ve just keyframed the size as there are only 5 title cards, but I’ve had this bug happen a couple of times on other projects so I don’t know if it’s something I’m doing wrong!