Jun
19
2019

Continue Coroutine after gameObject was disabled

So, customer wanted final changes few hours before deadline, to add hide/show feature (just regular disable-enable gameobject) for some animated UI elements. (Effects were using coroutine to set values and colors).

To my horror, after you disable and then enable gameobject, the coroutine is dead! And just calling StartCoroutine again resets the values for the loop, so it wouldnt look nice where the fading and UI values would restart everytime.

Enter quick hack, store loop values into variables at OnDisable() and then use them in OnEnable(), before starting coroutine again:

source:
https://gist.github.com/unitycoder/c62fb534982830bcab47a3fc7b182f28


About the Author:

.fi

Leave a comment

Connect

Twitter View LinkedIn profile Youtube Github Join Discord Twitch Instagram BlueSky

UnityLauncherPro

Get UnityLauncherPRO and work faster with Unity Projects!
*free unity hub alternative

@unitycoder_com

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.