So, I've a bunch of objects inside a composition and my ideia is the following:

I want to create an expression in one of them that will change the opacity of that object to 0 after a random time. Then I'm planning to apply this to all objects creating the effect of the objects disappearing at random.

I was looking on the web, and trying to play with this:

maxOffset = 20
offset = framesToTime(random(maxOffset));

But I can't make it work the way I described. What should happen is:

  1. Generate a random frame number between 0 and value of maxOffset;
  2. When the random frame number matches current time change object opacity to zero;

Thank you.

  • 1
    Just to get it right, your object disappears completely after a random amount of time and should no longer appear in your comp, right?
    – p2or
    Commented Jun 2, 2015 at 16:39
  • @poor exactly! thats what I'm trying to do.
    – TCB13
    Commented Jun 2, 2015 at 17:25

1 Answer 1


I'm not sure what the valueAtTime function is trying to achieve. That takes the value of the property at the given time. In the script you wrote it would sample the value of the opacity at a point a random number of seconds in the past, some time between the current time and maxOffset seconds ago. Unless the opacity changes during that time it won't do anything at all.

Expressions are Javascript, so you can use all the Javascript language elements, including if and else. Thus:

maxOffset = 20;
minOffset = 1;
if (time>random(minOffset, maxOffset)){0}else{value}

This will turn off the layer at some time between 1 and 20 seconds for each layer. If the opacity channel is already animated it will use the animated value up until the time it turns off. To change this so that it is 100% on until it turns off, substitute {100} for {value} in the last line


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.