Search Unity

How in the world do I nest Animations manually?

Discussion in 'UGUI & TextMesh Pro' started by FoWare, Sep 4, 2014.

  1. FoWare

    FoWare

    Joined:
    May 24, 2013
    Posts:
    13


    This Animation controller has all it's animation states nested under the controller. I think this is a great way to organize. Only issue is I can't do this myself, the only way I've seen to get this setup is with "Auto Generate Animation" when using a UI>Button, but if I try to setup this type of relationship with other objects manually, I simply can't nest the animations under the object.

    Functionally it's almost the same except other animation controllers can't access another controller's animations if they are nested, which is fine but I just want to know how to accomplish this. Is it possible to do this manually on our own?

    TL;DR: UIButton's Auto Generate Animation does something I can't seem to recreate.
     
    Stardog and rakkarage like this.
  2. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
  3. FoWare

    FoWare

    Joined:
    May 24, 2013
    Posts:
    13
  4. defaxer

    defaxer

    Joined:
    Nov 15, 2010
    Posts:
    140
    It is working and I can add new AnimationClips to Controller just fine, but when I try to add this clip to newly created empty state it gives me an error :
    Animation clip 'End' is not retargetable. Animation clips used within the Animator Controller need to have Muscle Definition set up in the Asset Importer Inspector.
    Any tips?
     
  5. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    I'm not sure. Is the clip an 'imported' clip. If it's an asset on the HD you probably can't add it as a child.
     
  6. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    Possible feature request: could we have AnimationClips be nested in the AnimatorController by default? I don't think I've ever once reused an AnimationClip in a different controller, and associating clips with the correct controller is....challenging at best.
     
    Rodolfo-Rubens and rakkarage like this.
  7. defaxer

    defaxer

    Joined:
    Nov 15, 2010
    Posts:
    140
    It's not "imported", I've just added it like this:
    Code (CSharp):
    1. AnimationClip clip = new AnimationClip();
    2. clip.name = clipName;
    3. AnimatorController controller = Selection.activeObject as AnimatorController;
    4. AssetDatabase.AddObjectToAsset(clip, controller);
    5. AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(controller));
    error appears when I try to assign such nested clip to motion field


    BTW, Is there a way to remove nested clip?
     
    Last edited: Sep 4, 2014
    futurlab_peterh and rakkarage like this.
  8. ChoMPi

    ChoMPi

    Joined:
    Jul 11, 2013
    Posts:
    112
    Here is the method Unity uses to generate a transition

    Code (csharp):
    1.  
    2. private static AnimationClip GenerateTriggerableTransition(string name, AnimatorController controller)
    3. {
    4.     AnimationClip animationClip = AnimatorController.AllocateAnimatorClip(name);
    5.     AssetDatabase.AddObjectToAsset(animationClip, controller);
    6.     State dst = AnimatorController.AddAnimationClipToController(controller, animationClip);
    7.     controller.AddParameter(name, AnimatorControllerParameterType.Trigger);
    8.     StateMachine stateMachine = controller.GetLayer(0).stateMachine;
    9.     Transition transition = stateMachine.AddAnyStateTransition(dst);
    10.     AnimatorCondition condition = transition.GetCondition(0);
    11.     condition.mode = TransitionConditionMode.If;
    12.     condition.parameter = name;
    13.        
    14.     return animationClip;
    15. }
    16.  
    PS: If you are interested i've made a little class to help me create animator controllers with custom states just like the Auto Generator in Unity. Here's the link: http://pastebin.com/ZLjZ1gda
     
    Last edited: Sep 4, 2014
    futurlab_peterh, Tim-C and rakkarage like this.
  9. defaxer

    defaxer

    Joined:
    Nov 15, 2010
    Posts:
    140
    Hey, thanks! This work just great!
     
    Tim-C likes this.