When OnBecameInvisible been called

Hi All,

I have this weird thing goining on. I use OnBecameInvisible when my character is no longer seen by the main camera. When it is not visible bu the main camera I start a coroutine:

void OnBecameInvisible()

        someComponent.enabled = false;


It works great utill I stop running the game in the editor (when I press the play button again to stop running the game)
and I get this console error :

Coroutine couldn’t be started because the the game object ‘guy’ is inactive!

guy is the name of my character where the script is attcahed.

Any ideas?

Thank u in advance

Probably an answer is too late, but today i spent some time with the same issue and find out a solution by using this method:

void OnApplicationQuit() {
    activated = false;

need to add if statement in your OnBecameInvisible() method, like this:

void OnBecameInvisible() {

    if(activated == true) {
        // your code


don’t forget to initialize “bool activated = true;” variable at beginning of the script.

you have Disabled the Guy by script but you didn’t enabled it after Coroutine so … SomeComponent.enabled = false; StartCoroutine(SomeCoroutine()); someComponent.enabled = true;

And Enjoy…Cheers…Don’t forget to mark the answer if helped you…