Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Persistent state between frames

  • Persistent state between frames

    Posted by ali kim on November 1, 2024 at 1:51 pm

    I have a layer with a car, and I have another Null layer with a speed controller that has manually placed keyframes.

    I want to control the car position according to those speed keyframes, i.e. accumulate traveled distance. For example, if the spped values on the first 5 frames are 1, 2, 3, 4, 5 then positions should be 1, 3, 6, 10, 15.

    I wrote this script and it works as intended:

    sourceLayer = thisComp.layer("Null 1");
    currentFrame = timeToFrames();
    
    sum = 0;
    for(i = 0; i <= currentFrame; i++) {
    sum += sourceLayer.effect("speed")("Slider").valueAtTime(framesToTime(i));
    }
    sum

    This becomes very inefficient as currentFrame increases. In reality I need some kind of persistent across frames storage, so I could just add one value to it every frame. Is that possible to do in Ae scripting system?

    ali kim replied 3 months, 2 weeks ago 2 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    November 1, 2024 at 10:42 pm

    Scripting is a completely different story, but you can’t do it with expressions. It’s not hard to figure out why it has to be that way. In AE you can move to any frame in the timeline and it needs to render. If that depended on whether some persistent variable might have been modified somewhere in the frames that you skipped over, chaos would ensue. It was a deliberate design decision that expressions have no memory.

  • ali kim

    November 1, 2024 at 11:13 pm

    I see, thank you, so how do I “script” this problem properly?
    Can I have a layer with manually controlled keyframes that change the speed of a car and have it’s position calculated in a sensible way?

  • Dan Ebberts

    November 2, 2024 at 12:51 am

    Scripting doesn’t operate in real time like expressions, it’s more suited to building and manipulating comps, layers, etc. in more of a batch environment.

    You may still be able to use an expression for what you’re trying to do, you just need to work around the “expressions have no memory” constraint. What is it, exactly, that you want to do?

  • ali kim

    November 2, 2024 at 2:03 am

    I built a panel (comp) that has layers for clear sky, clouds (two tiled copies back to back so I make them infinitely looped), morning and evening sun.

    Then I wanted to be able to build a hexagon ring out of these panels in the main comp, and have a null layer (in the main comp) where I control the look and feel of each panel, that is its sky layer, clouds layer (including their speed), sunrise, sunset position along with clouds highlights state that I made using tint and inner shadow etc.

    In the main comp I have a camera moving and rotating around a city, so I just wanted to build a controllable sky rig. The way I see it, you need to control the rig at the same comp/level as camera where you can set the state for each sky rig panel separately.

    I know programming and how to write external jsx and extensions, so that’s not a problem, I can build comps out of images, for example to make 3d buildings and hexagonal rings. But curiously enough, it seems that the only thing that stops me is that absence of global storage inside the project space.

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