I am making a player with a death animation, but whenever I call the animation it give me the error:
Coroutine couldn't be started because the the game object 'Player' is inactive!
This is my code for the animator:
IEnumerator Death()
{
yield return null;
trans.SetTrigger("Death");
yield return new WaitForSeconds(.2f);
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
// Start is called before the first frame update
void Start()
{
gameObject.SetActive(true);
rb = gameObject.GetComponent<Rigidbody2D>();
}
I’m wondering why gameObject.SetActive(true); located in Start method.
Start method will be invoked if the object is active. I mean that you don’t have to use SetActive(true); here.
I’m guessing you use coroutine on inactive object. If so, you have to activate a object by other object.
Please show me a whole code of yours.
I ended up making the animation in a different way, but I realized that in that animation I was manipulating 4 child objects, they may have been inactive. I believe that activating them in the player’s start function would solve it, thanks to everyone that helped.