Ah, I often moan about things in Unity being too difficult or weird for my brain and then struggle free in barely an evening. I stand by previous comments about how delightfully quick Unity is to get to grips with, even after lengthy off-periods playing through ill-advised prequels.
Today, then, let’s talk about animation systems.
At this point in time, Unity offers two different animation systems. One centres around the Animation component, the other the Animator component. I know naming things is the hardest part of sofware development, but this is exceptionally confusing.
The thing is that, when you set up a model import, it’s hard to tell what type of rig you want to create from an animated model — Legacy, Generic or Humanoid. I figured my mechs were Generic, even though they do tend to have humanoid characteristics.
Then I started to use them. I applied the Animation component to my game objects, think that would allow me to unlock their animations… But that was my first mistake. See, as soon as I started the game rolling in this state, Unity started spewing out error messages — “this animation clip must be marked as Legacy,” it screamed over and over again. I didn’t know what I was doing, so I dutifully regressed my imports to Legacy rigs.
The great thing about the Legacy system is that, coming out of half a lifetime modding Warcraft III, it matches my expectations of how one might interact with an animation system. You split up your model’s timeline into clips and get the game logic to tell the unit to play particular clips at particular times.
As previous demo videos have attested, I got that working just fine. I got my little mech seguéing between standing and jumping, landing and running…
A while later, I thought to myself, “No, ‘Legacy’ is a bad word. I can’t build the next ten years of personal projects on foundations I know are deprecated.”
I didn’t have the faintest idea what was going on, though. My first thought was that the Milkshape FBX exporter might somehow be producing some older format of FBX, and Unity was raising a stink about that. That would have been understandable, I guess, but would have put me right up shit creek seeing as I don’t know how to work any more modern 3D modelling software. (Besides, Milkshape is absolutely perfect for what I do, I don’t want to move on.)
In the end I went to the Unity forums. “I understand how I can make this message go away,” I began, “but why does it happen in the first place?” (Obviously I said it in a more timid and banterous way.)
The answer was simple enough. “You’re using an Animation component when the modern animation system uses an Animator.” Sure, that makes perfect sense…
Of course Mecanim is the shiny, new system that doesn’t at all match my expectations. Or rather, it still does, but under another layer of indirection, and I get the nasty feeling I’m fighting the engine by still scripting so much.
Ah well, any performance cost I incur by over-scripting should be nearly sidelined by my late 90s graphics.
See, Mecanim doesn’t just use animation segments that play when they’re told to, it uses a state machine middle-man. Instead of, you know, just scripting when animations play, you can set up conditions right in the animation system, completely independently of the underlying logic.
This concerns me a little, because the animation system doesn’t really know anything about the object — how it’s moving, whether it’s in the air or on the ground or not. It can’t be allowed to play clips off its own back because, well, it doesn’t know what to play — it can’t know what to play. Maybe something fairly concrete like a falling animation being followed by a landing animation…
No; even then, my mechs can hit the ground running. No sirree, the script has to win.
Of course, messing with such things, the pieces never quite go back together. I swapped my stuff over as best I could. but the affordances of the new system are just different enough to shatter a few things I was relying on.
Ah well — no pain, no gain. Better getting over this hump now than having to rebuild it all in a year or two when they finally give Legacy the chop and half my engine falls into the sea.
3 thoughts on “Blog 601: Mecanim”
Mecanim is awesome, for me.
I like it better than the legacy animation.
And it’s not hard to change from legacy to mecanim controlled animation.
Oh don’t get me wrong, I’m sure it is much better. I’m just a total amateur thrashing around in the dark. :]
I am also an amateur in sense of game development.
But once you got it, I think you’ll love the system more than the legacy one. 😀