Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Create animation clip and add it to timeline from script

Discussion in 'Timeline' started by Sergey_Droba, Jan 5, 2018.

  1. Sergey_Droba

    Sergey_Droba

    Joined:
    Nov 6, 2016
    Posts:
    52
    Hi,
    i'm trying to generate some animation clips from editor. I have many game objects.
    I create animation clips and it works in timeline but only in current session. If i restart a scene it losing link to clips.

    What i'm doing wrong? Should i create animation files to save them? Or how to add them to timeline file?

    Thank you!
     
  2. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    Yes! Animation files are referenced by timeline, so they need to exist as an asset.
     
    Sergey_Droba likes this.
  3. Sergey_Droba

    Sergey_Droba

    Joined:
    Nov 6, 2016
    Posts:
    52
    Thank you.
    Should i do it with AssetDatabase.SaveAssets() class or Timeline has something similar?
     
  4. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    Use AssetDatabase.SaveAssets. If you are generating timeline assets as well, make sure the timeline is added to the asset database before adding tracks.
     
    Sergey_Droba likes this.