0
\$\begingroup\$

I discovered a weird animation bug and have no idea how to solve it. Below you find the script I attached to my humanoid character.

using UnityEngine;
using UnityEngine.AI;

public class PlayerCharacter : MonoBehaviour {

    private Animator anim;
    private NavMeshAgent agent;

    private bool dead = false;

    void Awake()
    {
        this.anim = GetComponent<Animator>();
        this.agent = GetComponent<NavMeshAgent>();
    }

    public void Kill()
    {
        this.dead = true;
        this.anim.SetBool("Dead", true);
    }

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.X))
        {
            Kill();
        }
    }

    public bool IsDead()
    {
        return this.dead;
    }
}

My character makes use of the NavMeshAgent and can walk around and idle - everything works fine. But if I want to kill the player the dead animation loops continuously. This also happens if I change the death animation.

This is my AnimationController: enter image description here

As you can see, the transition has the condition "Death" with is set to true in the Kill() method. The code for walking and idling in combination with the NavMeshAgent is similar, but the script shown above doesn't work as expected and I have no clue why the animation starts to loop continuously (which looks a bit funny btw). Additionally the animation is not played to end, it restarts after a few frames.

Any ideas? I could also post a video of the behavior if it would help. Thanks in advance! :)

\$\endgroup\$
1
\$\begingroup\$

you didn't specify which unity version but I'll assume since this is only 16 hours old its at least 5.6. I believe your having the same issue I did and it would be related to the fact your death state is linked to the any and not the other 2. I had a similar issue with an animation not playing right and I had to create some extra transitions. also make sure your other 2 don't have exit times that tends to wack out the animations but what I would try and it may or may not work is create transitions from walkFWD to the death and then also make transitions from the Idle to the death. I have found sometimes unity when jumping from a state to another state without a direct transition in the newer mechanim (I'm assuming your using mechanim) does some wierd things.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Yepp, I removed the transition from any and added transitions from the other both states and it works like a charm! Thanks alot and have a nice day :) \$\endgroup\$ – Morph Jul 24 '17 at 20:17
  • \$\begingroup\$ no problem been using unity since version 3 and it has a lot of weird little quirks like that :) it was a shot in the dark because you didn't specify version and animations are different in different versions, but glad it helped :) \$\endgroup\$ – Jacqueline Loriault Aug 6 '17 at 5:23
0
\$\begingroup\$

Select the Unarmed-Death1 state, and if you double-click on the animation (motion) in it, you should see a Loop Time option. Just uncheck that and it should stop looping.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Hi @naturalbornlazy and thanks for your respone! :) There is no looping flag set and it also happens with other non-looping animations. \$\endgroup\$ – Morph Jul 24 '17 at 8:12
  • \$\begingroup\$ A little addition to the post above: Additionally the animation is not played to end, it restarts after a few frames. \$\endgroup\$ – Morph Jul 24 '17 at 8:22
  • \$\begingroup\$ Then I would assume your animator is just entering the Death state over and over again, since the only condition, Dead equals true, is still being met, and Any State includes your current state (I am not 100% sure about this but it would seem logical) \$\endgroup\$ – naturalbornlazy Jul 24 '17 at 9:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.