Search Unity

Help! Animation from Imported Model won't play even when Rig is changed to Legacy

Discussion in 'Animation' started by eruzatitania, Sep 26, 2013.

  1. eruzatitania

    eruzatitania

    Joined:
    Dec 16, 2012
    Posts:
    9
    Guys, I have been so stuck in my project. Please help me.

    Here's the scenario:
    -I import a lot of 3d models (but same bones, same texture and same everything except animations)
    -I'm using Unity 4.2 and by default, the setting under the Rig Tab is "Generic". When I play the Animation under the Animation Tab, it does play.
    -I deploy the model to the Scene, add other animations (of the same model) in the Animation Component under Inspector.
    -When I try to test the animation by using some codes, it can only play the model's own/original animation. The other animations don't play, errors occur and the Console says those should be set to "Legacy."
    -I change the setting under Rig Tab from "Generic" to "Legacy" and did the same on all models.
    -Before I test it with codes, I test it first under the Animation Tab. And it doesn't play anymore.
    -When I test it with codes, no errors occur but the model doesn't animate. :-(

    I made it work on a model but on most models, I can't.

    **if I change the Rig setting back to "Generic", I can play it under the Animation Tab but errors go back and I still can't play the animation through my codes. :(

    What is the problem? What should I do? Please help me.

    oh, and if you ask about the codes that I use... here they are

    var anim: Transform;

    function Update () {
    if(Input.GetKeyDown(KeyCode.E)){
    Debug.Log("animate idle");
    anim.animation.Play("idle");
    }
    if(Input.GetKeyDown(KeyCode.F)){
    Debug.Log("animate walk");
    anim.animation.CrossFade("walk");
    }
    if(Input.GetKeyDown(KeyCode.R)){
    Debug.Log("animate shake");
    anim.animation.CrossFade("shake");
    }
    }
     
  2. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,694
    The first step is to make sure everything's working in the importer. Don't think about the scene or your code until then.

    Since you're using the Animation component, you're using the Legacy animation system.

    (As a side note, you could consider switching to the Mecanim animation system. If you do, you'll have to change your code, and also set the Rig to Humanoid if possible.)

    If you're using Legacy, here are my recommendations:

    1. Start with your model. On the Rig tab, choose Legacy and click Apply. Then, on the Animation tab, get the animations working. If they don't work here, probably nothing else will work either. If they won't play in the Animation tab, please reply with a screenshot and any console errors.

    2. Once the model is working, do the same thing for the individual animation files. You may need to drag the model onto the Animation tab's preview window so you can view the animations. If they don't play, please reply with a screenshot and console errors.

    3. Add the model to your scene and select it in the hierarchy.. Open the Animation window (menu item Window > Animation). Select each animation from the drop-down and play it. Make sure that it plays through the Animation window. If they don't play, please reply with any console errors.

    4. Close the Animation Window. On the Animation component, assign an animation to the Animation field and tick "Play Automatically". Run the scene and make sure the model plays the animation.

    5. Add the animations from the separate files to the Animation component. Test them in the Animation window.

    6. Once you've confirmed that steps 1-5 work, then look at your code.

    I hope this helps, and good luck!
     
  3. eruzatitania

    eruzatitania

    Joined:
    Dec 16, 2012
    Posts:
    9
    Thanks! I'll try your suggestions and inform you of my output :D
     
  4. eruzatitania

    eruzatitania

    Joined:
    Dec 16, 2012
    Posts:
    9
    hi, it's me again...
    i've tried and retried many times but i had no success with my game project. here are the screenshots
    $0idle.png $3prep-for-anim.png $3prep-for-anim2.png $4my-anim-code.png
     
  5. eruzatitania

    eruzatitania

    Joined:
    Dec 16, 2012
    Posts:
    9
  6. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,694
    If you've had a chance to go through steps 1-6 in my previous reply, please let me know which step fails. In particular, does it work in the Animation view?

    Maybe it just needs to be set up a little differently. I may be misunderstanding your scenario, but typically you have a Player game object, or child object, with a SkinnedMeshRenderer and an Animation component. You don't actually add the idle.FBX to the scene.

    Presumably you've imported the Player model as Legacy. If so, then it should have an Animation component. From the Project view, expand the Idle asset and drag the Idle animation (the sub-asset with the gray play button icon) onto the Player's Animation component, adding it to the Animations list.

    Then open the Animation view (Ctrl/Cmd-6), select the Player in the scene, and select Idle from the drop-down. Make sure it plays on the Player model. If it does, repeat the process for Shake (that is, add it to the Player object's Animation component).

    Please give that a try and let me know if it works -- or let me know if I completely misunderstood what you're trying to do here. :)
     
  7. eruzatitania

    eruzatitania

    Joined:
    Dec 16, 2012
    Posts:
    9
    Yes, I had followed steps 1-6 that you've given me and still it doesn't work. The animation doesn't even play in the Animation View unless I drag its root model into the said view (example: i currently viewed model 'idle' and its animation in the Animation View; if i want to play the animation of 'shake', i have to drag the model of 'shake' first or else it won't work)

    and yes, i had been adding the animation (the sub-asset with the gray play button icon) to the Animation Component of model 'idle.'

    also, I've followed your suggestion -- to test the animation clips in the Animation Window -- but only the clip that has originally come from the model plays; all the rest can't be played. (example: I got model 'idle' to the Project and Scene and attached animation clips 'idle' and 'shake.' Only the 'idle' clip plays.)

    Oh, if you want to try solving the problem with the model.. here it is http://www.youtube.com/watch?v=dfzCbqiRbDE

    I had someone advise me to use Mecanim instead of Legacy so I'm still learning how to do it. But I very much prefer Legacy because it can be configured fast (I don't know how many steps to follow in Mecanim System yet) and because I used it and successfully made it work in a model, Skyrim Werewolf http://www.youtube.com/watch?v=LdXCgGFBkj8
     
  8. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,694
    Maybe I'm not understanding you, but it sounds it's one of these two problems:

    1. When using Legacy, the skeleton used by the shake.FBX animation (or any other animation) must exactly match the skeleton used by your Player object. Otherwise the animation will not play on your Player object. If this is the case, you have to use Mecanim to retarget the animation to Player's skeleton.

    2. But my best guess is that you haven't actually added the animation clip to the Player's Animation component. Follow these steps to fix it:

    a. Remove 'idle' and 'idle_2' from your Hierarchy (i.e., from the scene). They should not be there.

    b. In the Hierarchy, inspect Player. It should have an Animation component.

    c. In the Project view, expand idle.FBX. Drag the idle clip onto the Animation component's Animations list of the Player object.

    d. Repeat for the shake clip. Now your Player object should have an Animation component with 'idle' and 'shake' in the Animations list.

    e. Select the menu item Window > Animation.

    f. From the animation drop-down, select shake and press the play button. It should play.
     
    theANMATOR2b likes this.
  9. eruzatitania

    eruzatitania

    Joined:
    Dec 16, 2012
    Posts:
    9
    I've tried your suggestion # 2, sir. And it didn't work. :neutral:
    My aim in this mini project is to test out if I can invoke (through codes) the animations of models I desire to be enemies of a bigger game that I am devising. ;) it's not to test out the animations onto the Player itself because the Player is the generic FPS Player from unity package CharacterController.

    I'm still trying out your suggestion # 1 and am exploring Cinema4D to further it (I am a total newbie at modeling softwares.)

    Sir TonyLi, I thank you for your time and help and I'm sorry for the trouble. :D
    I will inform you of my output!
     
  10. eruzatitania

    eruzatitania

    Joined:
    Dec 16, 2012
    Posts:
    9
    Sir, how do I use Mecanim to retarget animation (if possible, multiple animations) to a model? I'm sorry, I don't know. I've tried viewing some tutorials in youtube but I hadn't found anything that teaches about multiple animation retargeting... :(
     
  11. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,694
    I feel like I'm being knighted. Just Tony is fine. :)

    To use Mecanim, watch this video a couple times: http://video.unity3d.com/video/7362044/

    When you import your model and the animation FBX's, on the Rig tab choose Humanoid: http://docs.unity3d.com/Documentation/Components/FBXImporter-Rig.html

    Then create an Animator Controller and edit it: http://docs.unity3d.com/Documentation/Manual/Bringingcharacterstolife.html
    To add an animation state, open one of the animation FBX's. Then drag the clip (with the gray play button) onto the Animator canvas.

    Finally, assign the Animator Controller to the Animator component on your character.

    Download the Mecanim Examples project or the Locomotion Starter Kit to play with more examples or see how the code works.
     
  12. eruzatitania

    eruzatitania

    Joined:
    Dec 16, 2012
    Posts:
    9
    Hello Tony :D
    thanks for the links! I have downloaded necessary files and have watched some videos on how to do Mecanim.
    also, I thank you for giving me the idea where the error resided which I had fixed and has allowed me to continue with Legacy Animations (implementing the Mecanim System for me will be for further development)
    here's some screenshots :)
    $problem.png

    once again, thank you for the idea you gave me. i couldn't have sought out the error without you. :)
     

    Attached Files:

    Last edited: Nov 1, 2013
  13. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,694
    Happy to help! (Mecanim is similar. Instead of adding those clips to the Animation component, you'll add them to the Animator view's canvas.)
     
  14. eruzatitania

    eruzatitania

    Joined:
    Dec 16, 2012
    Posts:
    9
    I'll try using it some other time :D
    When I finish my project, I'll let you know :)
     
    Hitulc19 likes this.