Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
2
Question by TheYokai · Aug 05, 2014 at 05:23 AM · c#animationanimatorenum

Using C# Enums to Control an Animator

So I have a GameObject with a C# script that has several enums which control the behavior of my object in game. For example:

     public enum MovementState
     {
         Idle,
         Hanging,
         Falling,
         Swapping,
         Snapping
     }
 
     public enum State
     {
         Inactive,
         Active,
         Matching
     }

I also have an animator on the same object which has a few different animations that I want to be able to control using the enums above. Should I make an int parameter for each enum in my Animator? Or should I control the animator through a switch statement in my C# code? Is there a way to nicely work with multiple enumerated states in Animator?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by fafase · Aug 05, 2014 at 05:32 AM

   "Should I make an int parameter for each enum?"

Your enum members are already integers. The first is given the value 0 and the following are increasing by 1. It is possible to control the value by giving an explicit int but I don't think you need that here.

   "Is there a way to nicely work with multiple enumerated states in Animator?"

Mixing different enums is not possible but you can mix enum of the same type by marking them as flag.

http://www.dotnetperls.com/enum-flags

In this case you would have both enums in one and you could have none (being just a 0 enum), one or many states at once.

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 TheYokai · Aug 05, 2014 at 05:52 AM 2
Share

I know that enums are ints. I also do not want to use one single enum statement for multiple object states. What I want to know is whether or not there's a good way to work with enumerated types inside my animator class or if it is better to use a switch statement inside of my C# script which manually sets which state should be playing.

If I try to send my enum value directly to my Animator parameter as an int, I can no longer see the enumeration 'name' that I have defined for it. This will make it harder for artists to work with my system as it requires specific knowledge of the enumeration order.

avatar image fafase · Aug 05, 2014 at 06:03 AM 0
Share

You can easily go back and forth between int and enum. Passing the int to the animator, you lose the name but you can get it back on the other side:

 print((EnumType)intValue);

you could come up with an editor script to show the Enum value converted from int.

avatar image
0

Answer by grovalmitch · Aug 06, 2014 at 06:54 AM

More about ....C# Enum

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.

Follow this Question

Answers Answers and Comments

23 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

Related Questions

How to change the speed of an animation? 1 Answer

What is the proper way to wait for an Animator Controller to update? 1 Answer

[Resolved]Animator.Rebind on instantiated child. 0 Answers

Playing animation at the start 1 Answer

Same Animator, different clips for different objects. 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