C# yield - Wait for a function to complete


I want to start a Coroutine where i can wait for functions to complete:

IEnumerator GamePhase(){
		       yield return Reveal();
		yield return null;

void Reveal(){
  ...do Stuff

to be honest, i don’t want to return anything, i just want to call a function and wait for it to complete until continuing…
unity throws an “cannot convert void to object” error … which is kinda understandable :slight_smile:

How can i use an endless loop and wait for functions to complete

Might be that i got that whole yield function wrong…

I wrote that answer many years ago when I had little experience on Unity. After all this time, looking back to my answer, I just laugh at myself :slight_smile: But I guess it’s a good thing. Instead of deleting my answer because of shame, I wanna keep it as a proof of my personal progress of experience.

Please don’t take my answer below seriously.

You don’t have to do anything special to wait for a function to complete.

The processor doesn’t go to next code line until a function which is called in previous line completes.

I’m sure you are aware of that. So, you should supply more details. Tell us what do you want to achieve? What type of behavior do you want ?

As I mentioned to other people earlier. “Yield” is like a lightsaber in the hands of a adopt jedi student. So dangerous.

Edit after detailed question:

There is some info about how to use yield in Unity Help Documents but I’ve never used it.

You can wait for an animation ends by checking its current time against its length in the update event.

If you don’t want to anything else until the animation ends, you can just quit the update event by using “return” keyword.

just the algorithm (not the exact script. this won’t compile) :

void Update(){
    if (Animation.CurrentTime < Animation.Lenght) return;

    DoSomeOtherWorkHere(); // this won't be called until the animation ends.

I assume that you start the animation in another place (or maybe automatically)