0
\$\begingroup\$

I have an Animator on this gameObject. The Animator hits one state when some parameters are true, it can transition to this state from any state. The parameters are fine because i can see in the animator that the state is getting hit when i want it to. The blue progress bar is showing, but the animation doesn't play on the screen in the game, it just shows the state before it. I have tried changing exit time, apply root motion, update mode, static batching. Nothing works Help pls internet gods

As requested here are some images, first this is my animator and the transition that is set up: (I have also tried this with the same transition but from flies buzzing directly and the same behaviour happens) enter image description here

Also here is what the animation state looks like and the preview of it, showing that it works in scene (just not in game) enter image description here

And here's how it behaves in game, as you can see the blue bar is progressing (and this is going into the state at the correct time, after dealing 2 damage to the fly, isDead gets set to true). However the only animation that plays is the fly buzzing one. enter image description here

Here's my code:

enter image description here

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FlyCombatAndFollow : MonoBehaviour
{
    [Space]
    [Header("References:")]
    public Animator animator;
    public GameObject fly;

    [Space]
    [Header("Character attributes:")]
    public int maxHealth = 2;
    int currentHealth;

    // Start is called before the first frame update
    void Start()
    {
        currentHealth = maxHealth;
    }
    public void TakeDamage(int damage)
    {
        currentHealth -= damage;
        //Play hurt animation 
        animator.SetTrigger("IsHit");
        animator.SetInteger("Hit", damage);

        if (currentHealth <= 0)
        {
            StartCoroutine(Die());
        }
    }
    public IEnumerator Die()
    {
        Debug.Log("Fly died");
        //play death animation
        animator.SetBool("IsDead", true);
        yield return new WaitForSeconds(1.0f);
        //Disable fly
        Destroy(fly);
    }
}

\$\endgroup\$
  • \$\begingroup\$ Please include a Minimal Complete Verifiable Example: every step a reader would need to follow to reproduce this problem in a new empty project. With that in hand, we can recreate your problem and test solutions to it, to make sure you get working answers. \$\endgroup\$ – DMGregory Mar 18 at 20:28
  • \$\begingroup\$ Given that you haven't provided full detail (avatar mapping, declaration of parameters, the code that calls the change of parameters, the animator component's parameters, etc.), I'll jujst ask: Are the name of the bones of the avatar's mapping are the same on the GameObject? since it is imperative that both names match, otherwise the State Machine will run, but with no animations. \$\endgroup\$ – LifGwaethrakindo Mar 18 at 20:38
  • \$\begingroup\$ Okay i've added a lot of detail now. And LitGwaethrakindo there is no Avatar as it's a 2D Sprite \$\endgroup\$ – Josh Bailey Mar 18 at 21:15

Your Answer

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

Browse other questions tagged or ask your own question.