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
0
Question by 1MachoKualquiera · Apr 01, 2015 at 05:09 AM · animationanimatorexceptionerror-messageanimation script

Animator.GotoState: State could not be found.

Okay, so i got this code (C#)

 using UnityEngine;
 using System.Collections;
 public class Stats : MonoBehaviour
 {
     public float Health;
     public bool Dead;
     private bool Invencible;
     private float Counter;
     private Animator Animator;
     public float DeathCounter;
     private bool AnimPlayed;
     private bool MovementDisabled;
     void Start ()
     {
         Animator = gameObject.GetComponent<Animator>();
         DeathCounter = 6;
     }
     void Update()
     {
         if (Health > 100) { Health = 100; }
         if (Health < 0) { Health = 0; }
         if (Health == 0) 
         {
             Die();
         }
         if (Invencible)
         {
             if (Counter <= 0)
             {
                 Invencible = false;
             }
             else
             {
                 Counter -= Time.deltaTime;
             }
         }
     }
     public void DealDamage (float Damage)
     {
         if(!Invencible)
         {
             Health -= Damage;
             Invencible = true;
             Counter = 1;
         }
     }
     private void Die ()
     {
         if (!MovementDisabled)
         {
             Dead = true;
             MovementDisabled = true;
         }
         if (DeathCounter <= 0) 
         {
             Respawn();
         }
         else
         {
             if (DeathCounter <= 5)
             {
                 DeathCounter = DeathCounter - Time.deltaTime;
                 if (!AnimPlayed)
                 {
                     AnimPlayed = true;
                     PlayAnim("Dead");
                 }
             }
             else
             {
                 DeathCounter = DeathCounter - Time.deltaTime;
                 PlayAnim("Idle");
             }
         }
     }
     public void PlayAnim(string Name)
     {
         Animator.Play(Name, 0);
     }
     public void Respawn ()
     {
 
     }
 }

And this animator (Please, tell me the animator navigation controlls) alt text

But, anywhere in the code, when i try to play the animation "Dead" using

 Animator.Play("Dead", 0);

it runs, and 2 seconds later (The code line is not even being executed)

Animator.GotoState: State could not be found UnityEngine.Animator:Play(String, Int32) Stats:PlayAnim(String) (at Assets/Systems/Character/Stat/Stats.cs:79) Stats:Die() (at Assets/Systems/Character/Stat/Stats.cs:67) Stats:Update() (at Assets/Systems/Character/Stat/Stats.cs:25)

The thing is, the animation plays fine. But the error makes me mad. With other animations it works perfect, and, i even tried playing the animation from other script, and, it don't shows any error. Is this a bug, or am i doing something wrong? Unity hates me. Thank you, and sorry for my english.

Comment
Add comment · Show 6
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 sumeeton · Apr 01, 2015 at 05:42 AM -1
Share

You are using the Class itself as variable..

Declaration should be:

 private Animator animator; // use small a

Change all the variable names in the script to animator

To avoid any confusion you may choose a different name for the variable, say: myAnimator

avatar image sumeeton · Apr 01, 2015 at 05:49 AM -1
Share

Additional note: use camel casing for variables (eg: myAnimator, playerHealth, playerScore) and use pascal casing for function and class names (UpdateScore, RespawnEnemy)

avatar image DoTA_KAMIKADzE · Apr 01, 2015 at 06:47 AM -1
Share

Use any casing you like just don't use the same na$$anonymous$$g case-sensitive as any of all your classes that you have in your project.

P.S. You can also start your fields with underscore "_" character, just the tip.

avatar image sumeeton · Apr 01, 2015 at 07:04 AM -1
Share

It's a standard program$$anonymous$$g practice to use camel casing and pascal casing and putting it to practice will help others understand your code and help you understand other's code more easily. Besides no one uses '_' underscore for the properties. It's a bad program$$anonymous$$g practice. You may use them for accessors.

avatar image AndrewGrayGames · Jan 14, 2017 at 02:53 AM 1
Share

While the discussion of program$$anonymous$$g practice can be a good thing, in this case, it's really superfluous. I'm also running into this problem and the discussion is completely unhelpful - the OP is trying to figure out why they're getting an Animator.GotoState exception. They're not the only one.

Show more comments

2 Replies

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

Answer by 1MachoKualquiera · Jan 16, 2017 at 07:37 AM

As @sumeeton pointed out, my problem was naming the variable the same as its class name. This way, I was accidentally referencing a static Animator class that doesn't contain the animation state I was calling. This could be your issue too, @Asvarduil. Thank you guys ^^

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
2

Answer by Vollmondum · Oct 23, 2019 at 03:12 PM

Actual problem is RENAMING your animations and animation states in Mecanim. Make sure those coinside.

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

6 People are following this question.

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

Related Questions

How would I switch between 2 animation states connected to 1 state under input? 0 Answers

Set the time of an animation keyframe per script? 0 Answers

How to run my jump animation in unity3d? 0 Answers

2D Animation Help, noob question 2 Answers

2D Animation does not start 1 Answer


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