Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Undo group problem

  • Undo group problem

    Posted by Edward Clayton on March 20, 2023 at 4:49 pm

    I’m creating a Script UI with a slider. While the user is changing the slider, a temporary shape layer is created in order to preview the effect. When they let go, the temporary layer is removed and the effect is applied.

    slider1.onChanging = function() {
        // this will get fired 100+ times
        // create shape layer to preview (adjust outPoint on the shape layer)
    slider1.onChange = function() {
        // this will get fired once
        // adjust selection

    Since the preview layer can get changed 100s of times in a few seconds, a clean undo group is important.

    My initial thought was to start an undo group on onChanging and close it on onChange. However the script is actually firing off with each change on the slider, so this doesn’t work as expected.

    My current workaround is to create an intentional undo group mismatch. This leaves the user with an annoying pop up “After Effects warning: Undo mismatch, will attempt to fix.” but it actually undos everything perfectly.

    Is there a better way to go about doing this? Or some other tricks to hack the history panel?

    Yoan Boisjoli replied 8 months, 2 weeks ago 2 Members · 3 Replies
  • 3 Replies
  • Yoan Boisjoli

    March 23, 2023 at 1:23 am

    Hi Edward! I’m not a pro with scripts but I think that instead of starting an undo group on onChanging and closing it on onChange, you can use the app.beginUndoGroup() and app.endUndoGroup() methods to manually start and end an undo group at the appropriate times.

    Here’s an example implementation:

    var undoGroupInProgress = false;

    slider1.onChanging = function() {

    if (!undoGroupInProgress) {

    app.beginUndoGroup("Preview Slider Change");

    undoGroupInProgress = true;


    // create shape layer to preview (adjust outPoint on the shape layer)


    slider1.onChange = function() {

    // apply the effect

    if (undoGroupInProgress) {


    undoGroupInProgress = false;



    With this implementation, the undo group is only started once when the slider is first changed, and is ended once when the slider is released. The undoGroupInProgress variable is used to ensure that the undo group is only closed if it was actually opened in the first place.

    This should avoid the “undo mismatch” warning and provide a clean undo history for your users.

    Hope this helps/work for you.

  • Edward Clayton

    March 23, 2023 at 4:17 pm

    Thanks for the response, Yoan!

    I actually tried this exact same thing and it still doesn’t work properly. There are no mismatch errors, but unfortunately it still treats each tiny change during onChanging as its own event.

  • Yoan Boisjoli

    March 23, 2023 at 7:22 pm

    Hmm.. Looks like we think alike!

    Maybe a better approach is to create a temporary layer on the first onChanging event and then update it during the subsequent onChanging events. This way, you only need to create one undo group when applying the effect in the onChange event.

    var previewLayer = null;

    function createPreviewLayer() {

    // Create your temporary shape layer here and set its outPoint

    // based on the slider value.

    // Return the created layer.


    function updatePreviewLayer() {

    // Update the outPoint of the previewLayer based on the slider value.


    slider1.onChanging = function() {

    if (!previewLayer) {

    previewLayer = createPreviewLayer();

    } else {




    slider1.onChange = function() {

    // Clean up the preview layer before applying the effect.


    app.beginUndoGroup("Apply Effect");

    // Adjust the selection and apply the effect based on the final slider value.


    // Reset the preview layer.

    previewLayer = null;


    This creates a temporary preview layer and updates it during slider adjustments. When the user releases the slider, the temporary layer is removed, and the effect is applied within a clean undo group. Hope this will give you the desired undo behavior without any warning pop-ups.

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