Search Unity

Mechanim Not Playing Layer Animation

Discussion in 'Editor & General Support' started by Ironic-Chef, Jun 19, 2013.

  1. Ironic-Chef

    Ironic-Chef

    Joined:
    Mar 7, 2013
    Posts:
    12
    Hi All,

    I've set up multiple animation controllers to allow my character to hold and use different items. The controllers are all identical other than changing the animation clips being used.

    When I drop any of these controllers manually into the animator, the second layer in the controller works as expected.

    However, if I assign a loaded controller at run-time, the base layer works properly, but the second layer animation is no longer applied. When I step frame during the run, the animation editor is *apparently* running the animation (I can see the progress bar advancing along the state icon) but there's no action in the actual game.

    Any thoughts?
     
  2. Ironic-Chef

    Ironic-Chef

    Joined:
    Mar 7, 2013
    Posts:
    12
    Further input - This behavior occurs in the compiled game as well as in the editor. I've also found that making a change to the default controller during run-time (trying to edit the controller's second layer animation speed while the app is running) also causes the animation controller to stop applying animation from that layer to the character.

    So, is this a bug, or is there some initialization step that I'm missing? My current code is entirely consistent with the suggested implementation of instantiated animation controllers from the Unity devs.

    I really need this to work, and at the moment I have no workaround.
     
  3. Marble

    Marble

    Joined:
    Aug 29, 2005
    Posts:
    1,268
    Well, if the runtime controller works when assigned before runtime but not when assigned during runtime, and that's the only difference, it sounds like a bug and should be reported. Runtime controller assignment is still very new. There appear to be a variety of other bald-faced bugs in Mecanim at the moment. E.g. transitions from a one-frame animation state = crash, avatar masks cannot be applied to individual animations, and more.
     
  4. Ironic-Chef

    Ironic-Chef

    Joined:
    Mar 7, 2013
    Posts:
    12
    Thanks - that's pretty much my conclusion. I was hoping that someone had experienced this and had a workaround.
     
  5. Ironic-Chef

    Ironic-Chef

    Joined:
    Mar 7, 2013
    Posts:
    12
    Problem solved! Hopefully this helps someone else.

    When switching RuntimeAnimationController objects during execution, layer weights are not preserved. By default it appears that Unity assigns a weight of '0' to all layers other than the base layer, and the only way to change this is via script. In my own case I was assigning weights to my default animation layer in the Start segment of my control script and I'd not thought to revisit that section of code. Assigning layer weights after reassigning the RuntimeAnimationController results in loaded animation operating as expected.

    So, while this is not technically a bug it definitely falls into the "you should explain some of this stuff a bit more thoroughly" category. I lost a good couple of days figuring this out.