Can I automate additional steps for "Duplicate"?

I use Timeline to spawn an object and move it from one position to another. This requires two tracks in my setup: Activation and Animation Tracks.

When I want to spawn another object that is doing the same thing, just at a different time, I duplicate these tracks, but also have to duplicate the GameObject in the Hierarchy and replace the references in the duplicated tracks to the new GameObject. These two steps (duplicate GameObject and replace references) I would like to automate.

Can I hook into the Timeline context menu to add my own “Duplicate” menu item? Is there a better way to do it?

Below you can find the problem described in a video, it’s just a 2 minute watch.

bump :slight_smile:

I don’t see a way to combine both steps (duplicate track + replace gameobject references) into one single operation.

However, you can still add a custom menu entry to replace the binding of a track with a new gameobject. It would then be a two step process:
1- duplicate track
2- right-click on the new track, then select your custom action.

Here’s a basic action to replace the binding of a track. It should show up in the context menu when right-clicking on a track.

[MenuEntry("Replace binding with new GameObject")]
public class ReplaceBinding : TrackAction
{
    public override ActionValidity Validate(IEnumerable<TrackAsset> tracks)
    {
        return ActionValidity.Valid;
    }

    public override bool Execute(IEnumerable<TrackAsset> tracks)
    {
        foreach (TrackAsset track in tracks)
        {
            var newGameObject = new GameObject();
            Undo.RegisterCreatedObjectUndo(newGameObject, "Replace binding");

            PlayableDirector director = TimelineEditor.inspectedDirector;
            Undo.RecordObject(director, "Replace binding");
            director.SetGenericBinding(track, newGameObject);
        }

        return true;
    }

    //Uncomment this method to assign a shortcut to your action
    /*[TimelineShortcut("Replace binding", KeyCode.B)]
    public static void HandleShortCut(ShortcutArguments args)
    {
        Invoker.InvokeWithSelectedTracks<ReplaceBinding>();
    }*/
}

8289959--1086662--upload_2022-7-18_13-52-7.png