Search Unity

Mecanim I hate you!

Discussion in 'Animation' started by ColpColtran, Nov 20, 2019.

  1. ColpColtran

    ColpColtran

    Joined:
    Oct 9, 2014
    Posts:
    27
    Hi,

    it is quite a long time Unity did switch to Mecanim, yet it seems lacking some features that previous animation system had.

    Mostly I am interested in playing animation in fixed time of X that is determined at runtime. So the animation should be played exactly for X seconds (and it is not possible to know what the X is until you need to play the animation).

    It might seem complicated, but basically the reason for this is that I want to be my animations designed around my RPG system, not the other way around. So if Fireball skill should be casted for one second, animation should last exactly that long. But a character can have his casting speed increased temporarily, hence the exact length of animation is unknown until the very moment that you want to play it.

    Mecanim doesnt seem to be able to do this thing reasonably.

    Things I have tried:
    -setting the speed of all states proportionally to animation length so each state would be exactly one second long and then use float multiplier. This solved the problem, but was tedious and more importantly, it doesnt work with animation override controllers.
    -trying to get the length of current state via code and then change the speed - that would work but the animator takes one frame to update so it doesnt work on the frame you start playing the animation. (seems very messy solution for me)
    -iteration over all the animation clips of animator until I find the one I want to play, get legth and change speed accordingly. (except I dont know the name of the clip I want to play since when I switched ot Mecanim, I stopped using them - I thought that was the whole point of Mecanim, that you can stop relyling on the animation names and use states instead and apply the behavior to multiple different characters)
    -making all the animations same length - that would solve it, but not sure if one can do this with reasonable effort in Unity, changing hundreds of clips

    Things I havent tried:
    -ritual sacrifice


    Is there really no reasonable way of getting length of a certain state via code?
    like animator.GetStateLength(string stateName)
     
    koirat likes this.
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    I hate Mecanim too, which is why I made Animancer (link in my signature). It gives you full access to the speed/time/length of animations whenever you want and doesn't force you to wait a frame before it responds to your commands.
     
  3. ColpColtran

    ColpColtran

    Joined:
    Oct 9, 2014
    Posts:
    27
    That actually sounds great.