Animator controller instances

What I’m trying to do is just that my models (2 or more) start walking when I click on them!

I have a model with 2 animations, let’s say “Walk” and “Idle”. Walk animation starts when my bool parameter “isWalking” is setted to true (currently handled by the behaviour when the model is clicked). This work fine as expected.

The problem comes when I have two or more instances of the model and its behaviour. When I set the paremeter “isWalking” true, both instances start the walking animation.

Is this the normal behaviour of mecanim? If it is, what are the best practices in order to control the animation states of two or more different model instances?

 Animator animator;
    void Start()
    {
        animator = GetComponent<Animator>();
    }

    // Update is called once per frame
    void Update()
    {
        if (animator.GetCurrentAnimatorStateInfo(0).IsName("Base.Walk"))
        {
            animator.SetBool("isWalking", false);
        }
        RaycastHit hit;         
        if (Input.GetMouseButtonDown(0))
        {
            var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out hit, Mathf.Infinity))
            {
                animator.SetBool("isWalking", true);             
            }
        }
    }

This is the second post on Unity answers I’ve found like this. I have the exact opposite problem I want to change the parameter once and affect all instances.

My guess is that either they significantly changed the way it works over the last 5 years, or your if (Input.GetMouseButtonDown(0)) code is getting called on all your instances. You could use a debug.log to check.

A line like Debug.Log(gameObject.name) will tell you the name of the attached object as well.

As it looks now, to solve my problem, I’m going to have to iterate through every instance to change them all and I really don’t want to do that. Or constantly check in update, on each instance, for a trigger that will set the bool (as you are doing here). I don’t want to do that either, since I only need it to happen once, not continually.