Yet Another Coroutine Failure Thread...

Hello all,

I’m an intern training to be a TA and want to try and tackle this seemingly simple problem by myself! Sorry if it’s obvious, I can’t figure out where the error is being thrown.

Error:
Coroutine couldn’t be started because the game object is ‘CoreOverload_x_EffectContainer’ is inactive!

Code:

public void PerformEffect(EffectBundle bundle)
    {    
        if(delay == 0)
        {
            DoEffect(bundle);
        }
        else
        {
            StartCoroutine(DelayedEffect(bundle));
        }
    }

    private IEnumerator DelayedEffect(EffectBundle bundle)
    {
        yield return new WaitForSeconds(delay);

        DoEffect(bundle);
    }

The error isn’t thrown at run time - only when the unit in questions comes into play. The delay is set to 2 seconds, for those interested. I’m pretty sure it’s something to do with these lines but if more info is needed, let me know.

Fox

That’s the issue. The game object in which the script is placed is not active. That’s a requirement for coroutines.

Hey, so how would I go about activating the game object?

I tried bundle.gameObject.SetActive(true) just above the coroutine call but am still receiving the same error.

In that case a parent game object is not active. Make sure that this one is not deactivated.

Just to confirm - an inactive parent automatically sets it’s children to inactive, but an active parent can contain both active and inactive children based on their individual states? (i.e. enabling the parent might not actually enable the child too, if it’s been deactivated) …

I ask because I think the bundle is the parent, but I am trying to write a log to debug beforehand to double check it is in fact active. I also tried just ‘gameObject.SetActive(true)’ - talking to our lead atm so will post back with response

Thanks for your help Dantus - the answer lied a little deeper and thus was not contained in any of the information I posted. I apologize for this.

Turns out in our bundle script which we use to import the game stuff never actually instantiated the game objects.

The below lines of code in a related script which the script in question pulled information from fixed it.

foreach(EffectContainer e in effects)
{
fxCon = EffectContainer.Instantiate(e) as EffectContainer;
fxCon.PerformEffect(this);
fxCon.transform.parent = transform;
}