Animation forgetting how to be an animation...

So it’s a pretty simple problem. The script is supposed to animate a door. The prints work fine, so I know the conditional portions of the code work, it’s just not playing the animation at all.

using UnityEngine;
using System.Collections;

public class UO_Door : UsableObject {

    public bool isOpen;
    [System.Serializable]
    public enum DoorOpeningDirection { Inward, Outward}
    public DoorOpeningDirection OpeningDirection;

    public override void DoInteract()
    {
        if (isOpen)
        {
            if (OpeningDirection == DoorOpeningDirection.Inward)
            {

                animation.Play("door_closing_outward");
                print("closing");
            }
            else
            {
                animation.Play("door_closing_inward");
                print("closing");
            }
            isOpen = false;
        }
        else
        {
            if (OpeningDirection == DoorOpeningDirection.Inward)
            {
                animation.Play("door_opening_inward");
                print("opening");
            }
            else
            {
                animation.Play("door_opening_outward");
                print("opening");
            }
            isOpen = true;
        }
    }
}

Does your door have Animation component?

Indeed it does.

Edit: like for my cheesy UDK test material ripoff? :smile:

1823537--116748--door_components.PNG

1 Like

Strange. Everything looks fine to me. Have you ever heard of Mecanim animations?

I have. But everything I hear about them makes it seem more like it’s meant for characters and other organic animation.

I am using it to make my FPS camera feel real (like dynamic movement etc). Sounds very wrong, but it works! :stuck_out_tongue:

Per your recommendation, I tried converting it over to Mecanim, but it’s still not working.

using UnityEngine;
using System.Collections;

public class UO_Door : UsableObject {

    public bool isOpen;
    [System.Serializable]
    public enum DoorOpeningDirection { Inward, Outward}
    public DoorOpeningDirection OpeningDirection;
    public AnimationClip openingAnimation;
    private Animator anim;

    public override void DoInteract()
    {
        if (!animation.isPlaying)
        {
            anim.SetBool("isOpen", isOpen);
        }
        
        if (isOpen)
        {
            isOpen = false;
        }
        else
        {
            isOpen = true;
        }
    }

    void FixedUpdate()
    {
       anim = GetComponent<Animator>();
       anim.SetBool("isOpen", isOpen);
    }
}

Try to uncheck Apply Root Motion.

That didn’t do it. But it’s worth noting that the collider moves. Just not the model itself…

I have had a lot of issues with Unity’s animation system just not making sense. Don’t feel bad. Try to find an example of what you’re trying to do and dissect it, you’ll figure it out.

1 Like