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 {
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.
	// Otherwise if the input is moving the player left and the player is facing right...
	else if(h < 0 && facingRight)
		// ... flip the player.


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?

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

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.

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 :))

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’.