- Home /
Unity bug? Coroutine couldn't be started inactive game object
I am aware that there are many posts about this coroutine thing with an inactive gameobject but mine is different. It seems more like a bug than something wrong with my code and heirarchy. I think I found a bug with Unity (where would I put something like a bug report anyway)? First off I would like to say that I am not using the newest version of Unity I am using version 2017.2.03f3. So this is what is happening. The second I stop Unity (by hitting the play button again once project is started) I get an error that coroutine couldn't be started because game object 'Cat' is inactive. It is as if my script runs for a very short time after I stop the project. There is no point anywhere where I set my game object 'Cat' to be inactive and it is active at the very start of my project. I am not loading any new scene all I am doing is hitting the stop button and getting this error. The code on my gameobject is simple so if it is any help here it is: using System.Collections; using System.Collections.Generic; using UnityEngine;
public class OutOfBounds : MonoBehaviour { public int maxTimeOffScreen; public AudioClip deathSong; public AudioSource music;
private void OnBecameInvisible()
{
Debug.Log("Possibly dead");
StartCoroutine(WaitForSeconds(maxTimeOffScreen));
}
IEnumerator WaitForSeconds(float duration)
{
for (int i = 0; i < duration * 10; i++)
{
yield return new WaitForSeconds(0.1f);
}
Debug.Log("Definitly Dead");
music.clip = deathSong;
music.Stop();
music.Play();
}
} Another thing that may be worth noting (although probably irrelevant) is that my gameobject cat is a child of an empty. However the script above is placed on my gameobject and not on the empty parent but in case somebody wants to try to replicate this I am providing all the details. Also my gameobject 'Cat' and its empty parent are a prefab. I thought I would put that in there because Prefabs sometimes glitch out and do weird things (particullary Canvas prefabs). I have a screenshot of the setup of the heirarchy, and also showing that the error appears last and only once.
Your answer
![](https://koobas.hobune.stream/wayback/20220612162933im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Unity Line Renderer drawing extra line to another point.. 0 Answers
Script only works if i enable/disable it in inspector 0 Answers
Animation load bug 0 Answers
TextMeshPro Object not updating in real time 0 Answers
Variable value not changhing 3 Answers