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
1
Question by BCU_Euden · Nov 22, 2013 at 01:48 AM · animationanimatormovement scriptanimator controller

Strange index < m_IntCount error using unity2D

I'm creating a 2D game using Unity. I've created a set of animations using a single sprite texture split into multiple sprites and then keyframed using unity's animation editor.

These animations are also controlled by an animation controller attached to the main sprite. In the animator the transition between animations follows the 2D example provided by unity. When the player idle the idle animation will play, when the speed is greater than 0.1 then the running animation will play. Back to idle if less than 0.1.

The script attached to the player sprite is the same player controller from the 2D example without the jump stuff added:

 using UnityEngine;
 using System.Collections;

 public class PlayerMovement : MonoBehaviour {
 [HideInInspector]
 public bool facingRight =true;



 //TODO Add variables for jumping

 public float moveForce = 365f;            // Amount of force added to move the player left and right.
 public float maxSpeed = 5f;

 private Animator anim;

 // Use this for initialization
 void Start () {
     anim = GetComponent<Animator>();
 
 }
 
 // Update is called once per frame
 void Update () {
     // TODO Ground checks and Jumping.
 }

 void FixedUpdate()
 {
     // Cache the horizontal input.
     float h = Input.GetAxis("Horizontal");

     // The Speed animator parameter is set to the absolute value of the horizontal input.
     anim.SetFloat("Speed", Mathf.Abs(h));
     
     // If the player is changing direction (h has a different sign to velocity.x) or hasn't reached maxSpeed yet...
     if(h * rigidbody2D.velocity.x < maxSpeed)
         // ... add a force to the player.
         rigidbody2D.AddForce(Vector2.right * h * moveForce);
     
     // If the player's horizontal velocity is greater than the maxSpeed...
     if(Mathf.Abs(rigidbody2D.velocity.x) > maxSpeed)
         // ... set the player's velocity to the maxSpeed in the x axis.
         rigidbody2D.velocity = new Vector2(Mathf.Sign(rigidbody2D.velocity.x) * maxSpeed, rigidbody2D.velocity.y);
     
     // If the input is moving the player right and the player is facing left...
     if(h > 0 && !facingRight)
         // ... flip the player.
         Flip();
     // Otherwise if the input is moving the player left and the player is facing right...
     else if(h < 0 && facingRight)
         // ... flip the player.
         Flip();


 }

 void Flip ()
 {
     // Switch the way the player is labelled as facing.
     facingRight = !facingRight;
     
     // Multiply the player's x local scale by -1.
     Vector3 theScale = transform.localScale;
     theScale.x *= -1;
     transform.localScale = theScale;
 }
 }

Also attached to the sprite is a rigidbody2D and a 2DBox collider.

When I click play to test this however I get the same error: index < m_IntCount over and over. The player sprites behaviour is as follows: he will begin the float upwards slowly, you can sill move him left and right but the run animation will not play.

Where am I going wrong?

Comment
Add comment · Show 2
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 KiraSensei · Nov 22, 2013 at 02:52 AM 0
Share

I don't see any weird thing in the posted code. Are you able to double click on the error ? $$anonymous$$aybe it shows you the specific line that rises this error.

avatar image BCU_Euden · Nov 24, 2013 at 08:58 PM 0
Share

The error is not able to be clicked on at all, double click it and you get nothing and no further details about it either.

4 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by aniv · Dec 18, 2013 at 09:30 PM

This error happened when I deleted Mecanim variable and created one with the same name, but different type. Try recreating your transitions.

Comment
Add comment · Show 1 · 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 felixpk · May 08, 2014 at 10:54 AM 0
Share

Great Solution, well observed!

avatar image
0

Answer by notreally · Feb 07, 2014 at 07:14 AM

I ran into the same problem. I wish I could give you a better answer but the issue appears to stem from transitions out of "Any State" in the Animator. I started my animations over but did not include transitions out of Any State and did not run into any issues.

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 taxvi · Feb 17, 2014 at 07:25 PM

I ran into same problem when I renamed a variable in mecanim and changed its type

just delete all the transitions that are using that variable and recreate them. it's kinda stupid but it works :))

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 HowBoring · Aug 26, 2014 at 11:30 AM

I got the same issue and now I've solved it. The reason of my problem was that TransitionConditionMode was wrong. I should've set the mode as 'If', but I set it as 'Equal'.

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

22 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

Related Questions

Character Animator controller/movement 1 Answer

How can I create a home position where my character returns to after every animation? 0 Answers

How can I change my AnimatorState instantly? 1 Answer

Animation Mecanim - Parts of model displaces after animating 0 Answers

Animator.CrossFade or Animator.CrossFadeInInFixedTime does not play animation after crossfading. 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