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

Editor OK - Hololens NO: Default clip could not be found in attached animations list - Legacy is ON

Discussion in 'Animation' started by santosluiz000, Dec 7, 2017.

  1. santosluiz000

    santosluiz000

    Joined:
    Dec 7, 2017
    Posts:
    1
    Guys,

    I'm building an application to run in Hololens. The animation is making a moviment and in another gameobject I use the same animation but in reverse mode.

    To make it I set the `speed` to `-1` like in this tutorial: https://answers.unity.com/questions/965066/unity-5-reverse-animation-play.html

    For example:

    GameObject 1: animation go ----->>>

    GameObject 2: animation back <<------


    The json file are like this:
    Code (JavaScript):
    1.  
    2. //"Go" way...
    3. {
    4.     "id": 1,
    5.     "name": "MyAnimation",
    6.     "path": "Animations/MyAnimation",
    7.     "speed": 1
    8.   },
    9.  
    10.   //"Back" way...
    11.  
    12.   {
    13.     "id": 2,
    14.     "name": "MyAnimation",
    15.     "path": "Animations/MyAnimation",
    16.     "speed": -1
    17.   },
    My script for call the json and set the animation

    Code (CSharp):
    1. public void SetAnimation(Step step, GameObject object3d) {
    2.         TextAsset json = Resources.Load<TextAsset>("JsonData/animations");
    3.         List<PrefabAnimation> animations = JsonConvert.DeserializeObject<List<PrefabAnimation>>(json.text);
    4.  
    5.         foreach (PrefabAnimation animation in animations) {
    6.             if (animation.id == step.animation) {
    7.                 AnimationClip anim = Resources.Load(animation.path.ToString()) as AnimationClip;
    8.                 anim.legacy = true;
    9.              
    10.                 if (object3d.GetComponent<Animation>().GetClipCount() != 0) {
    11.                     List<AnimationState> states = new List<AnimationState>(object3d.GetComponent<Animation>().Cast<AnimationState>());
    12.  
    13.                     foreach (AnimationState state in states) {
    14.                         object3d.GetComponent<Animation>().RemoveClip(state.clip.name);
    15.  
    16.                     }
    17.                 }
    18.  
    19.                 object3d.GetComponent<Animation>().clip = anim;
    20.                 object3d.GetComponent<Animation>().AddClip(anim, animation.name);              
    21.                 object3d.GetComponent<Animation>().Play(animation.name);              
    22.                 object3d.GetComponent<Animation>()[animation.name].speed = animation.speed;
    23.                 object3d.GetComponent<Animation>().playAutomatically = true;
    24.  
    25.             }
    26.         }
    27.     }
    1: The path for animations come from `json`
    1: I'm using the same animation file for "go" and "back" animation way;
    2: The "go way" animation all is works perfectly (Editor and Hololens)!
    3: The "back way" Unity Editor all works perfectly but in Hololens the not. The debug says: "default clip could not be found in attached animations list"
    4: All animations are in "Legacy Mode":



    How I can solve it?