Search Unity

Adding embedded animation into Animator

Discussion in 'Animation' started by Martijn Hendriks, Oct 16, 2013.

  1. Martijn Hendriks

    Martijn Hendriks

    Joined:
    Feb 5, 2013
    Posts:
    2
    Hey guys,

    I'm trying to figure out how the Mecanim system works and how we can use it for our model pipeline.

    We've created an importer inside of the Unity Pro editor so our modelling department can easily import their FBX-files for different types of items (they have additional information inside the user data that we read and apply to the model). Once this importer is completed, an asset bundle is created from the model that can later be downloaded and used by our main application.

    I want to do as much work inside this importer as preparation for the model, so that our amin application can easily work with it. As of now, we are working with the old animation system and I'm trying to let Mecanim work with the importer, but I encountered some things that you can hopefully help me with:

    When I import a model with an animation backed into it, how can I automatically attach it to the Animator component? What I understand from the tutorial is that Unity automatically creates an Animator component to the root of the model, and I need to add an Animator Controller (RuntimeAnimatorController?) to it, which has the imported animation clip attached to that. But how can I do this within Editor code? Since I can't find the animation clip and I can't seem to create the RuntimeAnimatorController.

    Thanks in advance!
     
  2. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,698
    If you import the rig as Humanoid or Generic (both Mecanim types), Unity will add an Animator component. If you import the rig as Legacy, it will add a (legacy) Animation component.

    Mecanim works differently from legacy. You don't add to a list of animation clips. Instead, you build an animation state machine that also includes transition and blend tree data. So, in Mecanim, it doesn't make sense to automatically add an animation clip without also specifying its context in the animation state machine.

    Also, Unity hasn't yet exposed the functionality necessary for us to edit Animator Controllers in scripts, although I've read that this might be in the 4.3 release.
     
    Last edited: Oct 16, 2013
  3. Martijn Hendriks

    Martijn Hendriks

    Joined:
    Feb 5, 2013
    Posts:
    2
    Hey Tony,

    Thanks for your answer. I know that I also need to set the context in the Animator Controllers, but for now I can get away with only one animation clip as default state (dragging the animation clip into the newly created animator controller). Unity not having exposed the scripting functionality yet gives me the conclusion that this system isn't ready for our importer, so we'll have to wait for the next version of Unity.

    On a side note: I've seen that the storing of Animation components in each node is removed with the Mecanim system. Is there a way to still have two game objects within one animation that operate independently from the animation?

    Let me explain: Modelling has created a vehicle, and every door in that vehicle is animated in one animation. What our importer does is distribute the animation clips on the relevant imported game objects (importer.generateAnimations = ModelImporterGenerateAnimations.InNodes;) and call the seperate animations so that we can open each door separately, instead of the one animation to open all doors at the same time. This was working like a charm in the old system. Does anyone have any idea if this is also supported in Mecanim? Multiple Animator components? Or inside the Animator Controller?

    Again, thanks in advance
     
  4. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,698
    I don't see why you couldn't use multiple Animator components (Generic rig for doors).

    BTW, this might not be relevant, but you can have an Animator component and an Animation component on the same object. Just make sure they operate on different bones. My characters' body movement uses a Humanoid avatar controlled by an Animator. Facial animation uses the legacy system controlled by an Animation component.