Menu

Tutorial 83: Semi-Automatic Animation

Joe Clay | Aug 11, 2017

Edit: Oops. I just realized I left a patch from my previous video over top of this one. I'm sorry if that made the code a little illegible for a moment. I wish YouTube would let you reupload over the old one like Vimeo does. Anyway, the code is below.

Yes, that was a Lil Wayne reference.

This week's After Effects tutorial shows you how to use markers to trigger and retime animations contained in a precomp from a main comp. It is based on Dan Ebberts' Triggering Animation with Markers expression with a couple of differences. First, Dan's technique uses a layer with the markers on it—we use comp markers because we finally have scripting access to them. Second, this version retimes animations using split markers while Dan's just triggers the action. To split a marker, hold option and then click and drag on the marker. I've never noticed these split markers in AE until about a week ago, so I'm doubting they were available when Dan wrote this excellent expression.

How it works

First, you animate everything in your precomp. Then you put named comp markers split around the action. Then you just put that precomp into other comps, add the expression below, and put split markers on it with the name of the action you want to put. As a side benefit, since they're comp markers, they come in with the precomp when you add it to your main comps. The best part is that this expression is completely portable to any precomp since it uses time remapping.

//Trigger and Retime Precomped Animations: Apply to Time Remap
action = comp(name);

n = 0;
if (marker.numKeys > 0){
    n = marker.nearestKey(time).index;
    if (marker.key(n).time > time){
        n--;
    }
}

if (n == 0){
    0
}else{
    m = marker.key(n);
    myComment = m.comment;
    try{
        actMarker = action.marker.key(myComment);
        originalStart = actMarker.time;
        originalEnd = originalStart + actMarker.duration;
        newStart = m.time;
        newEnd = newStart + m.duration;
        linear(time,newStart,newEnd,originalStart,originalEnd);
    }catch (err){
        0
    }
}

Other uses

Check out Triggering Animation with Markers to see how you can use this to animate characters. You can even use it to set up various elements—like transitions—in a single precomp and sequence them in your main comps. And if you're building up a brand package or a library of elements you can add elements to those precomps by animating new stuff and putting in a marker at any time without breaking anything. I'm not sure what would happen with overlapping markers since I didn't put any logic in there for that, so you might need to duplicate precomp layers in your main comp to overlay elements. I believe it'll probably just jump to the second animation at the point where the markers overlap.

I hope you enjoy this one. I'm standing on the shoulder of a giant for this one, but I'm pretty proud of how I was able to improve it. I'm going to implement it in a few projects and see what other amazing uses I can find for it! I encourage you to do the same and tell me about it! Hit me up @workbench_tv!

If you'd like to help support Workbench, check out my Patreon page. Thank you for even considering clicking this link to support what I'm doing. I appreciate it.