Search Unity

Override Animation Clip asset on Timeline

Discussion in 'Timeline' started by Wrymnn, Jun 22, 2018.

  1. Wrymnn

    Wrymnn

    Joined:
    Sep 24, 2014
    Posts:
    383
    We need to override and add data into Animation Clip which resides on Timeline

    upload_2018-6-22_7-51-16.png

    is it possible?

    We would like to add custom fields into this animation clip asset, so they are editable in inspector:

    upload_2018-6-22_7-52-51.png
     
  2. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    It might be possible by extending AnimationPlayableAsset and writing your own inspector, but you will likely run into problems in a few places because there are some assumptions in the timeline editor that AnimationPlayableAssets (i.e. animation clips on AnimationTracks) are the only type for AnimationTracks.
     
  3. Wrymnn

    Wrymnn

    Joined:
    Sep 24, 2014
    Posts:
    383
    I have overridden AnimationPlayableAsset (CustomAnimationPlayableAsset), but it does nothing. I cannot pick my class when creating clip for animation on timeline, nor Animation Clip on timeline contains fields I added into that new class.
     
  4. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    Animation Playable Assets weren't intended to be extended, so that's not unexpected.
     
  5. Wrymnn

    Wrymnn

    Joined:
    Sep 24, 2014
    Posts:
    383
    This is what you mentioned.

    So it is not possible to include custom fields as I have shown in original post.
     
  6. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    No, it looks like there isn't an easy way to do it, but what are you trying to do with it?
     
  7. Wrymnn

    Wrymnn

    Joined:
    Sep 24, 2014
    Posts:
    383
    We need to define additional properties to animation clip placed on Timeline, that artists can define. This is then used in our system, but we cannot use mecanim.

    E.g. if Timeline is stopped, should the clip playing skip to its end, or to its first frame?
     
  8. julienb

    julienb

    Unity Technologies

    Joined:
    Sep 9, 2016
    Posts:
    177
    You can create your own track, derived from AnimationTrack, and your own clip, derived from AnimationPlayableAsset.
    Code (CSharp):
    1. public class CustomAsset : AnimationPlayableAsset {
    2.     [SerializeField] public int Myint;
    3. }
    4.  
    5. [TrackClipType(typeof(CustomAsset))]
    6. public class CustomAnimationTrack: AnimationTrack {}
    7.  
    If you use a custom track, it will let you create the type of asset you want. You can also write a custom editor for your asset and it will be displayed in the inspector when selecting a clip. By default, the internal values for AnimationPlayableAsset will be displayed, with your custom fields after.
     
  9. Doronn

    Doronn

    Joined:
    Sep 17, 2018
    Posts:
    8

    I know this is really old.
    But since no one else said it.
    No. this does not work.
    It requires to implement a custom editor for each of these types.
    which means needing to copy the internal code for the editor scripts and modifying them.
    Instead of being able to override the these scripts in a normal C# fashion.

    Unity 2018.4.6
     
  10. adriandevera

    adriandevera

    Joined:
    May 18, 2013
    Posts:
    8
    The class AnimationPlayableAsset is no longer in untiy2019. I do see a
    AnimationClipPlayable but there is no interface to serialize it.
     
  11. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    Make sure you are including the UnityEngine.Timeline assembly in your .asmdef. Timeline became a package in 2019.1, so it now needs to be explicitly referenced.
     
  12. adriandevera

    adriandevera

    Joined:
    May 18, 2013
    Posts:
    8
    I apologize for not being clear. I am developing an import tool which creates prefabs and animations within it from a spriteimporter. The generated Asset contains sprites and AnimationClips that are read only as a result of AddObjectToAsset(). I am trying to implement a way to add animation events without duplicating the animation clips and instead directly using the generated Asset. It looks like AnimationClip and AnimationClipPlayable are both non-serializable. The method julienb mentioned seems impossible. I cannot inherit from the class because they are "Sealed" classes". Is there any way to circumvent this?

    Thanks!
     
    Last edited: May 25, 2020
  13. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    Ah, ok...AnimationPlayableAsset is a timeline type, and it seems like you aren't using timeline.

    AnimationClip is not extendable because it is an asset. AnimationClipPlayable is a runtime representation only and is not intended to be serializable.

    I'm not sure if you can instance the events on an animation clip. I believe they are all the same for the same clip, so you would need to duplicate them.

    Alternately if you are using timeline, you can add signals to the track with the animation clip.