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

after effects randomise timing with expressions

Community Beginner ,
Feb 05, 2025 Feb 05, 2025

hi, I am pretty new to using after effects expressions and I am not quite sure how to solve my problem and i also found no working solution on the internet.

 

so I want to animate objects with always one in the background and one in the foreground and want to alternate them - this i figured out works with giving one layer:

 

rate = 1/1;

posterizeTime(rate);

seedRandom(index, false);

random(0,100) < 50 ? 0 : 100;

 

and the other one:

 

if(thisComp.layer(index+1).transform.opacity==0)100;
else 0;
 
now comes my breaking point: I have a lot of these alterning pairs and I dont want them to all switc at the same time but rather randomized. I´ve tried several options working with offset, startTime/endTime or durations and either I did it wrong or it was the absolute wrong approach to my problem.
(e.g. pair 1 always switches on frames with :10 and pair 2 on frames with :15)

I am also working on a file with around 400 layers which also moves me to find a simple solution to my problem. 

 

(I also wanted it to only randomize between second 1 and 6 but I am more frustrated about finding a solution to the timing problem)

 

thank you soo so much in advance!

TOPICS
Error or problem , How to
818
Translate
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

correct answers 1 Correct answer

Community Beginner , Feb 06, 2025 Feb 06, 2025

Hi @Hani ElTiby ,

thank you very much for your help and quick response!

 

Unfortunatly I think I didn't quite understand your code so I wasn't able to make it work.
But I found another solution that seems to work with:

seedRandom(index, true); 

minFrames = 100; 

maxFrames = 200; 

frameHold = Math.round(random(minFrames, maxFrames));

currentFrame = timeToFrames(time); // Aktuelles Frame der Komposition

 

switchTime = Math.floor(currentFrame / frameHold);

 

(switchTime % 2 == 0) ? 100 : 0;

and:

if (thisComp.laye

...
Translate
Adobe Employee ,
Feb 05, 2025 Feb 05, 2025

Hi @emma_7029,

Thanks for the question. Sorry you were not able to get n answer from an expert or team member. I did a little searching and found that if you add a couple more lines of code for the first data set, you may be able to randomize objects more easily. Try:

rate = 1/1;
posterizeTime(rate);
seedRandom(index, false);
switchTime = random(1, 6); // Random time between 1 and 6 seconds
timeToSwitch = Math.floor(time % switchTime) == 0;
timeToSwitch ? 0 : 100;

I hope that helps. Let me know if it does.

Take Care,
Kevin
 

 

Kevin Monahan - Sr. Community & Engagement Strategist – Pro Video and Audio
Translate
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 Beginner ,
Feb 06, 2025 Feb 06, 2025

Hi @Kevin-Monahan ,

thank you so much for your quick reply and help!

 

Unfortunately this did not seem to be the solution. All the layers are still switching at 1s/2s/3s/... 
I was just wondering whether it could be due to the rate that is set. Is there a way to randomize that?

 

Thank you so much and take care,

Emma

Translate
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
Participant ,
Feb 06, 2025 Feb 06, 2025

Hi Emma, Try this
random time visibility.png
Notice that the controller comes right after the randomized layers so it dynamicly count the layers above, by using it's own index in the random() function.
If you have layers above the randomized layers you may set the first random parameter manually or by pickwipping the first layer and get it's index
for example : rand = random(thisComp.layer("Medium Royal Blue Solid 2").index, index);
here are both expressions
the Controller layer first

posterizeTime(effect("Posterize")("Slider"));
rand = random(thisComp.layer("Medium Royal Blue Solid 2").index,index);
hide = Math.floor(rand);

then the opacity

hide = thisComp.layer("Controller").effect("Hide")("Slider");
if (hide == index) {value} else {0}
Translate
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 Beginner ,
Feb 06, 2025 Feb 06, 2025
LATEST

Hi @Hani ElTiby ,

thank you very much for your help and quick response!

 

Unfortunatly I think I didn't quite understand your code so I wasn't able to make it work.
But I found another solution that seems to work with:

seedRandom(index, true); 

minFrames = 100; 

maxFrames = 200; 

frameHold = Math.round(random(minFrames, maxFrames));

currentFrame = timeToFrames(time); // Aktuelles Frame der Komposition

 

switchTime = Math.floor(currentFrame / frameHold);

 

(switchTime % 2 == 0) ? 100 : 0;

and:

if (thisComp.layer(index+1).transform.opacity == 0) 100;

else 0;

 

Thank you all very much for your help! 

Translate
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