Search Unity

Unable to build AnimationClip at runtime

Discussion in 'Animation' started by GnarleyMidget, Jan 29, 2016.

  1. GnarleyMidget

    GnarleyMidget

    Joined:
    Nov 6, 2015
    Posts:
    4
    I need to be able to dynamically build usable AnimationClips at runtime based on data that's unknown at build time. I'm currently using Version 5.2.4.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Experimental.Director;
    3. public class PivotController : MonoBehaviour {
    4.     void Start () {
    5.         var posxKeys = new Keyframe[3];
    6.         posxKeys[0] = new Keyframe( 0.0f, 0.0f);
    7.         posxKeys[1] = new Keyframe( 4.0f, 1.0f);
    8.         posxKeys[2] = new Keyframe( 8.0f, 0.0f);
    9.         var curve = new AnimationCurve(posxKeys);
    10.  
    11.         var clip = new AnimationClip() { legacy = false };
    12.         clip.SetCurve("", typeof(Transform), "localPosition.x", curve);
    13.  
    14.         Animator animator = gameObject.AddComponent<Animator>();
    15.         var mixer = new AnimationMixerPlayable();
    16.         mixer.AddInput(new AnimationClipPlayable(clip));
    17.         animator.Play(mixer);
    18.     }
    19. }
    20.  
    This controller works when applied to a gameObject and run in the editor. The same code fails when compiled and executed, with the following error -

    "Can't use AnimationClip::SetCurve at Runtime on non Legacy AnimationClips"


    If I set legacy = true the error messages go away, but the animation then fails in both Editor and Runtime.

    There has to be some way of doing this in a stand alone executable. In a somewhat related issue, there also seems to no way of creating a looping clip at runtime (clip.wrapMode = WrapMode.Loop doesn't do it). As near as I can tell the only way to do this is to serialize the Animation clip, modify the property, and reapply - which is not an option outside of the Editor. Why are there no dynamic runtime options available?
     
  2. pierrepaul

    pierrepaul

    Unity Technologies

    Joined:
    Jun 19, 2012
    Posts:
    162
    Its currently not possible to create Animation at runtime ( unless using Legacy )

    We are working on adding that soon.
     
  3. GnarleyMidget

    GnarleyMidget

    Joined:
    Nov 6, 2015
    Posts:
    4
    I'm willing to live with Legacy animationClips for the time being, but I don't seem to be able to make that work either.

    What would I have to add to the above sample (besides legacy = true) in order to get it to work?
     
  4. GnarleyMidget

    GnarleyMidget

    Joined:
    Nov 6, 2015
    Posts:
    4
    Ok - fixed it. I was attempting to use the Animator component to play a legacy clip. If I use the Animation component instead then this sample works at Runtime. Thanks.

    Animation animation = gameObject.AddComponent<Animation>();
    animation.AddClip(clip, "test");
    animation.Play("test");
     
    Bunny83 and deus0 like this.
  5. commodore

    commodore

    Joined:
    May 30, 2012
    Posts:
    40
    Cool, do you know when we will be able to do it? I'm currently able to create animations at runtime in the editor
     
  6. deus0

    deus0

    Joined:
    May 12, 2015
    Posts:
    256
    I am also waiting on this! I believe its been a couple of years haha
     
  7. Lawlets

    Lawlets

    Joined:
    Mar 1, 2018
    Posts:
    1
    @deus0 It's work now. You just have to set your animationClip legacy to true before call the setCurve function


    Code (CSharp):
    1. AnimationClip animClip = new AnimationClip();
    2. animClip.legacy = true;
    3. animClip.SetCurve("", typeof(), $"{nameof()}", YourAnimationCurve);
     
    deus0 likes this.
  8. moisturizor

    moisturizor

    Joined:
    Feb 1, 2017
    Posts:
    2
    Hello! When is this supposed to happen? Because I do really need this feature! Thanks
     
    mcl-dev and HulloImJay like this.
  9. rickknowles

    rickknowles

    Joined:
    Apr 21, 2018
    Posts:
    7
    Ditto - can someone from unity explain the limiting factor please ? It seems like the sort of thing that isnt depending on specific hardware acceleration etc. Is it a licensing issue ?
     
    TobyWu likes this.
  10. rickknowles

    rickknowles

    Joined:
    Apr 21, 2018
    Posts:
    7
    This is doubly important given
    a) how much Unity has been hyping Timeline as being the way to manage animations and
    b) the fact that Timeline doesn't support legacy animations at all (it rejects the clips on the standard animation tracks)

    I have a set of custom timeline playable assets that except for this would be able to runtime generate the animations I need, but because of this seemingly arbitrary limitation it's all unusable.
     
    mcl-dev likes this.
  11. ValiantTechStudios

    ValiantTechStudios

    Joined:
    May 10, 2020
    Posts:
    7
    This is something that I really need. I can't believe that coming soon is now 4 years ago. When exactly is soon?
     
  12. morph_jhKim

    morph_jhKim

    Joined:
    Aug 28, 2020
    Posts:
    4
    We are working on adding that soon.???

    Ok... I am still waiting.
     
    mcl-dev, craftsmanbeck and Sprawl like this.
  13. mcl-dev

    mcl-dev

    Joined:
    Feb 22, 2016
    Posts:
    5
    more than 5 years is soon for Unity apparently
     
  14. Ben1138

    Ben1138

    Joined:
    Mar 17, 2013
    Posts:
    2
    This feature is REALLY needed! Does someone know a workaround for this, besides writing some sort of manual transform manipulation from scratch....
     
    alvaro_perez_omnidrone and deus0 like this.
  15. Cameron_SM

    Cameron_SM

    Joined:
    Jun 1, 2009
    Posts:
    915
  16. Tulrath

    Tulrath

    Joined:
    Feb 1, 2015
    Posts:
    13
    Any updates on this? This issue has been open now for almost 6 years.
     
  17. Cameron_SM

    Cameron_SM

    Joined:
    Jun 1, 2009
    Posts:
    915
    The unity dev that responded to this back in 2016 hasn't posted on the forums since 2019 so probably doesn't even work there anymore. I seriously doubt this is even on their radar.
     
  18. Abhiwan_Pawan

    Abhiwan_Pawan

    Joined:
    Jun 16, 2021
    Posts:
    2
    Can't use AnimationClip::SetCurve at Runtime on non-legacy AnimationClips

    _JS_Log_Dump @ Build.framework.js:2.
    How long we have to wait for?
     
    LuLusg and aurelioprovedo like this.
  19. TigerHix

    TigerHix

    Joined:
    Oct 20, 2015
    Posts:
    69
    Unity: Soon™ we will implement this very important feature, but we think acquiring 100 companies first is more important...
     
  20. MingZiJiaoZhongGuo

    MingZiJiaoZhongGuo

    Joined:
    Apr 3, 2021
    Posts:
    4
    In 2022, you can only create legacy animation at runtime with Unity, what a time to be alive!
     
    pulecz, Pblu and TigerHix like this.
  21. KnightHuy

    KnightHuy

    Joined:
    Apr 28, 2023
    Posts:
    3
    Now 2023 and I still waiting for it
     
  22. andrew_unity628

    andrew_unity628

    Joined:
    Apr 1, 2020
    Posts:
    9
    Bump. Crazy this still isn't implemented. This affects game developers. We need to architect around this and it compromises the product.
     
  23. TigerHix

    TigerHix

    Joined:
    Oct 20, 2015
    Posts:
    69
    Why is exposing a few public APIs so hard? Given how broken most new packages are, we Unity developers are completely fine even if you expose obscure APIs that are mostly unusable. We have went through that anyway...
     
  24. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,769
    @pierrepaul it is better to respond to devs, if there is no plan on related fix, rather than let people hanging.
     
  25. Nad_B

    Nad_B

    Joined:
    Aug 1, 2021
    Posts:
    722
    He's probably not working at Unity anymore...

    Edit: he's still around, last time on forums: Aug 24

    Allez @pierrepaul svp, une petite reponse de votre part serait la bienvenue... on attend cette feature depuis 2016 :(
     
  26. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,769
    I don't know. I still see having Unity badge. Person never been really active here.
     
  27. patrick_Drake

    patrick_Drake

    Joined:
    Jul 2, 2023
    Posts:
    18
    Two weeks tm*
     
  28. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,769
    Just assume for your own sake, whatever you expect here it never will happen. So find your own way for a solution.
     
  29. Nad_B

    Nad_B

    Joined:
    Aug 1, 2021
    Posts:
    722
    Well he's still at Unity, just saw him few seconds ago in Unite 2023 Keynote giving the 1st talk saying how Unity is great and how the next versions would be even better!

    Hope that includes the solution to this 7 years old feature request :D
     
  30. TechPulse_Monkey

    TechPulse_Monkey

    Joined:
    Jun 11, 2018
    Posts:
    1
    still waiting for it in 2024