• 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
0
Question by scottstephan · Jan 23, 2016 at 02:09 AM · animatormecanimstate-machine

Animator SubState always plays Default even with a Behavior

Hey all,

Trying to set up a simple system that looks like this:

Animator Starts -> Animator goes to SubState "idle" -> A script fires to choose 1 of 6 random states -> That state plays and loops.

Here's what happens: Everything works, the script chooses the correct random state, but the Animator ignores my transition preferences and instead ALWAYS plays the default state that comes from Entry. What's the solution here? Animator: alt text

Sample Transition:

if(stateIndex > x)...

OverrideCode:

 public class randomSubStateManager : StateMachineBehaviour {
     public int numStates;
 
      // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
     override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
         int randoState = Random.Range(0, numStates);
         Debug.Log("controller chose rando index: " + randoState);
         animator.SetInteger("stateIndex", randoState);
     }


[2]: /storage/temp/62380-anim1.png

anim1.png (55.2 kB)
anim1.png (55.2 kB)
Comment
Add comment · Show 1
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 incorrect · Jan 23, 2016 at 03:02 AM 1
Share

Probably the problem is that animator transition occurs before your script execution. Try adding empty state and transitions from it to those idle states.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Buka · Mar 21, 2018 at 03:38 PM

I have this problem too and cannot find solution, why no one answering on these questions? In my case with just testing animator, even though states have conditions to exit state and go to another state machine, it loops back to default state. Not sure, kind of ignore conditions if go to exit state...

Comment
Add comment · 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
0

Answer by root-talis · May 11, 2020 at 06:59 PM

I just managed to make a smiliar setup work by throwing a default empty state into the sub-state machine and putting the randomizing behaviour on that default empty state.

alt text alt text

I'm surprised that 4 years later it's such a struggle to find a cookbook solution for such a trivial task. Shame on you, Unity.


image-1.png (137.6 kB)
image-2.png (15.1 kB)
Comment
Add comment · 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

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

38 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 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Mecanim transition retargeting and conditional exit to any state? 0 Answers

Transition to multiple states from Entry Node in Unity 5 1 Answer

Mecanim state that keeps last pose? 0 Answers

Checking Transitions in Animator 0 Answers

Mecanim - State Behavior - Select motion clip to play at runtime 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