• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
14
Question by Cygon4 · Nov 26, 2012 at 02:35 PM · animationmecanimtransitionfsm

How Complex Should Mecanim State Machines Be?

I'm toying with some Jump'n Run character controls like in those those old twitch action console games (run, dash, slide under obstacles, zig-zag wall-jump, ledge hanging, etc.)

Now I've only added a few animations to the character (and half of them don't even have proper transition animations yet) but my Mecanim Animator state mac$$anonymous$$ne is also getting nigh unmanageable:

Screenshot of my Mecanim Animator state mac$$anonymous$$ne

I've looked and blend trees and maybe I can merge the "Stand", "Walk" and "Run" animations into a single state and decide the "Jump" and "RunJump" states via conditions on the transitions, but it wouldn't do much good.

Sub state mac$$anonymous$$nes also don't seem to be particularly suited to relieving me of the maze of transitions that is slowly developing.

Is it normal for those state mac$$anonymous$$ne to get that complex? Can anyone recommend measures to simplify my state mac$$anonymous$$ne?

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ThePunisher · Nov 26, 2012 at 07:39 PM 0
Share

So what is different between RunFall and Fall, or RunJump and Jump?

avatar image Cygon4 · Nov 26, 2012 at 07:59 PM 0
Share

"Jump" is a vertical jump, legs together, very low horizontal momentum. "Fall" is the normal falling pose when walking off a platform or letting go of a ladder.

"RunJump" is a running jump, legs split, like a hurdler, with great horizontal momentum. It would look silly to suddenly take the free-fall pose after that, so the fall uses the "RunFall" pose. Unless momentum is lost (eg. player hit a wall), in which case it'll turn into a normal "Fall".

avatar image ThePunisher · Nov 26, 2012 at 09:22 PM 0
Share

Hmm, it almost seems like you can combine the similar states, but I'm at a loss at the moment as to how to account for them within the newly combined state (at least in an easier to follow manner).

Are you finding a lot of repeated code too, or is it just hard to following state transitions?

avatar image Cygon4 · Nov 28, 2012 at 11:42 AM 0
Share

Of course not, duplicate code is a cardinal sin ;)

I'm a software developer, so I feel more at home on the code side. In code, I can just decompose this into logical components, eg. maintain player state in a shared object and use a design akin to the strategy or state pattern to isolate swimming, walking, climbing, jumping, rope-swinging etc. into pluggable behaviors. Which allows me to extend the player movement controller without adding complexity.

But in Mecanim, it seems the idea is to lay out the whole world state graph in one big diagram. Unless I'm missing something, which is the point of my question.

I'm thinking of trying to combine the (stand,walk,run), (jump,runJump), (fall,runFall) etc. with blend trees and choosing the right transition animations (eg. run to runJump) by setting up appropriate conditions.

And I've yet to try out if switching the Mecanim Animator state machines on the fly is possible. If that works well, I could give each Behavior class its own animation state machine.

2 Replies

· Add your reply
  • Sort: 
avatar image
30
Best Answer

Answer by Cygon4 · Nov 28, 2012 at 05:12 PM

I have dug out a thread from the Unity forums where a user with 700 animation clips asks the pros whether Mecanim will support t$$anonymous$$s and is given some concrete advice:

Q: We had around 700 animations on the player (that number is still rising BTW) and I was wondering if mecanim will be able to handle such a number?

A: Well the intended design here is to use sub statemac$$anonymous$$nes. About performance it doesn't matter how many states exists, what counts is how many transitions exist in the current state(s) and how many animations are currently being blended (on all layers combined)

After looking at your graph I would recommend making 4 sub state mac$$anonymous$$nes.

Jump + Fall - Walk + Turn - Crouch - Prone

Then each of these areas could have the space and layout they deserve.


UPDATE: After experimenting with sub state mac$$anonymous$$nes and blend trees for a w$$anonymous$$le now, I am slowly figuring out how to effectively use them.

T$$anonymous$$s would be my recommendation to other people finding t$$anonymous$$s topic:

  1. Blend trees can cut away entire dimensions of the problem space. If your character animates differently based on speed, health or other properties, but essentially still does the same t$$anonymous$$ngs, you can use blend trees to kill any complexity that would arise from t$$anonymous$$s right away (and you can nest blend trees, too).

  2. Create layers for any animations that need to be superimposed on others (a typical example is shooting, w$$anonymous$$ch could happen w$$anonymous$$le holding onto a ladder, jumping, running or squatting). Layers let you can decide whether these superimposed layers override bones or only contribute (bone masks control w$$anonymous$$ch bones are affected).

  3. Whatever animations remain now should be organized into groups and put into sub state mac$$anonymous$$nes. A sub state mac$$anonymous$$ne is actually a folder, not another state mac$$anonymous$$ne. Transitions never go to a sub state mac$$anonymous$$ne, but to a specific state contained in a sub state mac$$anonymous$$ne. Likewise, transitions out of a sub state mac$$anonymous$$ne don't just go up, they lead to a specific state outside the sub state mac$$anonymous$$ne (and possibly inside another sub state mac$$anonymous$$ne).

To provide an example for how I resolved the messy situation that lead me to ask t$$anonymous$$s question, here's the revised version:

Root state mac$$anonymous$$ne

With hanging, kneeling and sliding being sub state mac$$anonymous$$nes. Here's the kneeling sub state mac$$anonymous$$ne, for example:

Kneeling sub state mac$$anonymous$$ne

I left the basic ground-based motion (running, jumping and falling) in the root state mac$$anonymous$$ne. Many of those states are actually blend trees (for example 'Locomotion' is a blend tree between standing, walking and running based on speed, same goes for 'Jumping' w$$anonymous$$ch blends between a standing jump and a running jump based on speed).

So the moral of the story is, don't fear sub state mac$$anonymous$$nes and know all the tools at your disposal in Mecanim - w$$anonymous$$ch is a bit difficult since the Unity docs currently only describe the what, but not the how or why. I hope t$$anonymous$$s helps other new users finding t$$anonymous$$s post :)


statemachine-root.png (27.6 kB)
statemachine-kneeling.png (28.3 kB)
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Brogan89 · Mar 16, 2016 at 08:31 AM 0
Share

Hey this was really valuable, thank you. I am currently working with a sprite animator, and the list is getting high. The transitions are doing my head in.

I have a question, though, within the script for 2D sprite animations, what would be the best way to call the animations. I am using boolean at the moment, just switching sprite sheets on and off. But I can see this getting pretty complicated as it grows too. - Hope you can give a tip. Cheers!

avatar image Lupod · Apr 05, 2016 at 07:22 PM 0
Share

I am not sure if this has changed since you've answered but what you say in point 3 about StateMachines is not true: "Transitions never go to a sub state machine, but to a specific state contained in a sub state machine. Likewise, transitions out of a sub state machine don't just go up, they lead to a specific state outside the sub state machine (and possibly inside another sub state machine)."

You can make transitions from the StateMachine itself to a state or another StateMachine and vice versa. As there are no Motions on a StateMachine, Transitions have no exit time and no FixedDuration but they can have conditions.

avatar image
3

Answer by Paulius-Liekis · Nov 28, 2012 at 02:42 PM

Yes, state mac$$anonymous$$nes can get pretty big :) I attached a BlendTree defining movement of character in "Battlefield - Bad Company" (obviously not made in Unity). T$$anonymous$$s is only for movement. There was another same size for shooting and a couple more for cutscene and similar stuff :)

So yeah, you can expect the state mac$$anonymous$$ne to get quite big for detailed character setup.

alt text


blendtreemoving.png (130.2 kB)
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Cygon4 · Nov 28, 2012 at 04:34 PM 0
Share

Well, I was looking for a way to avoid this mess, not for encouragement to accept it as the way things are ;)

avatar image jwinn · Dec 08, 2012 at 11:52 PM 0
Share

Thanks for posting that bad company blend tree; is there a higher-res version of that somewhere?

avatar image anadin · Feb 10, 2013 at 04:23 AM 0
Share

Yeah it would be very cool to see a higher res version of it

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Mecanim - transition from run to jump 1 Answer

AnimatorTransitionInfo.IsName() Not Working 1 Answer

Not able to use a Vector as a condition in Mecanim? 2 Answers

How to stop mesh disappearing during Animator state transition blend time? 1 Answer

What are those white curves in the animation transition panel - And can I read it in script? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges