#How to wait until coroutine inside of nested function is complete?

1 messages · Page 1 of 1 (latest)

obtuse hull
#

Hi, I have FunctionA() and FunctionB().

FunctionA has a coroutine inside of it that gets called. It's a for loop with a yield return new WaitForSeconds() at the end of each loop. During each loop, FunctionB is as such GameObject[] objs = FunctionB(). FunctionB has another coroutine inside of it using a for loop.

How can I wait for FunctionB to complete before continuing with the rest of the loop within FunctionA?

wooden harness
#

Do you mean that FunctionA and FunctionB are coroutines, which return IEnumerator?

#

That doesn't match what you're describing here, so probably not

#

If so, then you cannot make either function "wait" for a coroutine to finish

#

this would freeze the game

forest crystal
#

if, within a coroutine, you yield a coroutine/ienumerator, it waits for that subcoroutine to finish before continuing. that's the only way to realistically "wait for" it to be done

wooden harness
#

yeah, something like

IEnumerator Foo() {
  yield return Bar();
  Debug.Log("Done");
}

IEnumerator Bar() {
  yield return new WaitForSeconds(1f);
}
forest crystal
#

there's a different way to "wait" that.. i don't think is super useful, but i'm not sure what your current set up is

mental pine
#

If FunctionA is not a coroutine it can't wait for anything.

fair mortar
#

I need to point out that if you want to await the result from FunctionB then async is the better solution
Though this depends on your skill level