Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Persistent state between frames

Explorer ,
Oct 31, 2024 Oct 31, 2024

Copy link to clipboard

Copied

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?


TOPICS
Expressions , Performance , Scripting

Views

155
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 31, 2024 Oct 31, 2024

Copy link to clipboard

Copied

If your keyframes are linear and they don't happen every frame, you can probably gain some efficiancy by using a linear keyframe integrator, as discussed here:

https://www.motionscript.com/articles/speed-control.html#linear

but otherwise, theres no reliable way do persistent variables with expressions.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 01, 2024 Nov 01, 2024

Copy link to clipboard

Copied

LATEST
Is that possible to do in Ae scripting system?

 

Long and short: No.

 

Mylenium

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines