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
Leave a comment
Recent posts
- UnityHub: Enable built-in Login Dialog (no more browser login/logout issues!)
- Use TikTok-TTS in Unity (with WebRequest)
- Create Scene Thumbnail Image using OnSceneSaved & OnPreviewGUI
- webgl+javascript TTS
- Using Moonsharp (LUA) + Unity Webgl
- Using 3D gameobject prefabs with Unity Tilemap + NavMesh Surface
- Custom Unity Hub Project Template Preview Image/Video (using HTML+CSS in package description)
- Check if point is inside polygon 2D (using line intersection)
- UnityHub: Enable Create Project Button (without having to select Cloud Organization)
- UI: Make Tooltip background fit Text content length
- Pong-Wars in Unity
- Install Android SDK+JDK+NDK for Unity (without AndroidStudio or Unity Hub)