Strange situation about WaitForSeconds

Hi there.
I have two scripts, one of them derieved from “object”, and other from “MonoBehaviour”

In first script I have this

public virtual MyCustom removeChild(MyCustom child)
            if ( != null)
                foreach (MyCustom elem in childsList)
                    if ( ==
						int itemIndex = childsList.IndexOf(elem);
						childsList[itemIndex].target.transform.SetParent(GameObject.Find("Disabled items").transform);
            return child;

And in second script ("MyCustomGameObject, for example), I have this

public void StartOff() {
		Debug.Log ("Worked");
		StartCoroutine ("SetOff");

	IEnumerator SetOff() {
		Debug.Log ("log?");
		yield return new WaitForSeconds(1f);
		Debug.Log ("logged");
		this.gameObject.SetActive (false);

And when I play, I get two debug messages - “Worked” and “log?”.

So, here is a question:

Why my code runs only before “yield return new WaitForSeconds”???

Coroutines are only implemented in Monobehaviour objects so in your custom object when you return your new WaitForSeconds IEnumerator the function ends like it would in another function if you were to return any other value.

Make sure the object with MyCustomGameObject component is active.

Make sure the MyCustomGameObject component is enabled.

Make sure nothing removes that game object from the scene, or deactivates it or the component.

Make sure Time.timeScale is not 0.

A coroutine will only work with all that, deactivating or destroying a game object that started a coroutine will stop that coroutine at that moment, and if the objects was already deactivated the coroutine will run until the first return statement. Aslo, the WaitForSeconds return depends on the timeScale, if it’s 0 the 1 second will never happen.