Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Linking the points of a 4-Colour Gradient effect to a Null

  • Linking the points of a 4-Colour Gradient effect to a Null

    Posted by Filippo Marchetti on January 29, 2025 at 11:22 am

    Hello.

    I have a solid (same size as the comp) with a 4-colour gradient effect applied to it.

    I’d like to link each point of the gradient to a null, while keeping their original positions intact.

    Basically I’d like the points to follow the transformations of the null (scale, position, rotation).

    I tried asking a few AIs, and every expression I was provided with gave me the same error, specifically “Array can’t expand to more than one value”.

    I’d kindly ask you to help me achieve what I’m after and to help me understand the whole system better.

    I encountered similar issues in the past with other workflows, and I’d generally like to learn how to link the position of a point (Many after effects are controlled by points, like the light sweep for example) to a null, while keeping its original position.

    If I pickwhip the point’s position to the position of the null, it shoots out of the composition and I cannot keyframe it.

    I attached a screenshot of the error I get.

    “Ai_Gradients_Controller” is the Null I mentioned at the begionning, and this is the expression I applied to the 4-color gradient point in question:

    // Get the null layer
    var nullLayer = thisComp.layer(“AI_Gradients_Controller”);
    // Get the initial position of the gradient point
    var originalPoint = thisProperty.valueAtTime(0);
    // Get the current position of the null layer
    var nullLayerPosition = nullLayer.transform.position;
    // Calculate the initial offset between the original point and the null layer’s initial position
    var offset = [originalPoint – nullLayerPosition, originalPoint – nullLayerPosition];
    // Apply the null layer’s rotation to the offset
    var rotatedOffset = rotateVec(offset, degreesToRadians(nullLayer.transform.rotation));
    // Add the rotated offset to the null layer’s current position
    [nullLayerPosition + rotatedOffset, nullLayerPosition + rotatedOffset];
    // Function to rotate a vector
    function rotateVec(vec, angle) {
    var x = vec * Math.cos(angle) – vec * Math.sin(angle);
    var y = vec * Math.sin(angle) + vec * Math.cos(angle);
    return [x, y];
    }

    Thank you very much for the help.

    Dan Ebberts
    replied 2 weeks, 5 days ago
    2 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    January 29, 2025 at 12:08 pm

    I think all you need is something like this:

    L = thisComp.layer("Null 1");
    fromComp(L.toComp(L.anchorPoint))
  • Filippo Marchetti

    January 29, 2025 at 12:40 pm

    I will test this as soon as I’m home.

    In the meantime, thank you very much! 🙂

  • Filippo Marchetti

    January 29, 2025 at 3:48 pm

    I get no errors, but the point moves to the middle of the frame and I cannot keyframe it.

    I’d like the point to keep its original position.

    Thank you very much

  • Dan Ebberts

    January 29, 2025 at 4:11 pm

    If you want it track the movement of the null, you’d have to do something like this (but the point won’t move until you animate the position of the null):

    L = thisComp.layer("Null 1");
    p0 = L.toComp(L.anchorPoint,0)
    p1 = L.toComp(L.anchorPoint)
    value + (p1 - p0)
  • Dan Ebberts

    January 29, 2025 at 5:18 pm

    Another possibility is to just provide a static reference point, then you don’t need to animate the null to see the effect. In this example I use the center of the comp as the reference point (p0):

    L = thisComp.layer("Null 1");
    p0 = [thisComp.width,thisComp.height]/2;
    p1 = L.toComp(L.anchorPoint)
    value + (p1 - p0)

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