Search Unity

Feature Request: Clone a TimelineAsset in memory from code

Discussion in 'Timeline' started by FU_JPS, Sep 7, 2021.

  1. FU_JPS

    FU_JPS

    Joined:
    Nov 21, 2012
    Posts:
    12
    I would really appreciate the ability to clone entire TimelineAssets in memory from code.
    Instantiate doesn't work because the tracks reference the original, and CopyAsset is inconvenient for us.
    I know this issue has been brought up a few times in the past, so I know I'm not the only one:

    Calling Instantiate on a TimelineAsset breaks all the child tracks - Unity Forum
    Create a copy of a TimelineAsset to modify at runtime - Unity Forum

    For our use case, we have a lot of large timelines in our project (ones that reference a lot of large character animations). We have a "timeline viewer" scene where our designers can choose characters and costumes to load into the scene and play any timeline of their choosing. There are two major issues we have:
    • For whatever reason it seems the mere act of loading and playing back a timeline (!) changes the original asset somehow. Git sees the files are changed and designers unwittingly push data they don't remember changing.
    • In certain situations we need to modify tracks at runtime without modifying the original timeline asset. For example, if a character is wearing a certain costume we may want to apply an override track that animates bones that only exists in that costume.
    Originally I was using Instantiate to copy the timelines during playback, oblivious to the referencing issues, and it worked for us for the most part. The issue is that our project is still stuck on Unity 2018 (!) and in the process of trying to upgrade our project to a newer version I discovered that recent versions of Timeline now complain when trying to create the override track I mentioned above because the parent track doesn't actually belong to the instanced timeline I'm trying to add it to. (Sorry, I hope this sentence makes sense.)

    As a workaround, since this "timeline viewer" is only ever run in the editor*, I switched to using CopyAsset to duplicate the timeline into a temporary directory in the project that I told git to ignore. Unfortunately, our timelines are large so duplicating them on disk and waiting for the asset database to refresh, etc. takes a really long time. As soon as I implemented this the designers have been complaining that it takes forever to play a timeline now.

    At the moment I'm trying to duplicate the tracks recursively by hand. We are only using animation, activation, audio, and group tracks, along with a handful of custom tracks, so it may be feasible, but I would be really grateful if there were an official documented method. (I'd really like to avoid using reflection and whatnot to mess around with timeline internals, especially as they might change in later versions.) Naively, it seems like CopyAsset already knows how to do the hard work; if only there were a "CopyAssetInMemory"...


    * Our company only produces the character and animation assets so we generally always work in-editor and iteration time is a factor. The final build is produced by a separate team at another company who then compiles the timelines into their proper scenes so the override tracks, etc., do not need to be created at runtime in the actual build.
     
  2. FU_JPS

    FU_JPS

    Joined:
    Nov 21, 2012
    Posts:
    12
    It occurred to me that even if this feature were implemented we probably wouldn't be able to upgrade our Timeline package for a long time anyway.

    For now we're going with the "duplicate tracks by hand" method. We only use a limited subset of track types so it's sufficient enough for the time being.