Coroutines and loading screens
So i have a simple issue.
I'm executing a large block of code within a coroutine. Simple example:
IEnumerator perform_async()
{
LoadingScreen.SetActive(true);
yield return null;
// call heavy function here which takes a while to complete
LoadingScreen.SetActive(false);
}
In this example, LoadingScreen is a unity UI object so in order for it to become visible before the big function executes, i have to return null once so it appears.
.
Now let's say that this LoadingScreen has a text log on it. I can call a function, AddLogTextLine, which creates a new UI text block and appends it to the log. The problem is, if i do this, the log items don't become visible until after the heavy function ends.
.
When the AddLogTextLine function is called, I tried making it create the text object within a coroutine (so it would be a nested coroutine) but that doesn't seem to help. How can i add log items to the loading screen from the heavy function and have them appear at the same time they are created?
Answer by WainWork · Feb 01, 2019 at 08:42 AM
You may try break apart your large function and return null after every part
Follow this Question
Related Questions
StopCoroutine() Not Working 2 Answers
Coroutine, while, and Waitforseconds 1 Answer
"Can't add script behaviour AICharacterControl. The script needs to derive from MonoBehaviour!" ? 0 Answers
Why isn't my coroutine working when I call it from another script. 0 Answers
How do I stop an automatically repeating Coroutine? 1 Answer