Skip to content

Instantly share code, notes, and snippets.

@unitycoder
Created November 26, 2025 09:46
Show Gist options
  • Select an option

  • Save unitycoder/2c2be3aa54b1150db485b01389b317e1 to your computer and use it in GitHub Desktop.

Select an option

Save unitycoder/2c2be3aa54b1150db485b01389b317e1 to your computer and use it in GitHub Desktop.
unity return value from ienumerator

basic method

void Foo()
{
    StartCoroutine(Bar((bool myReturnValue) => {
        if(myReturnValue) { ... }
    });
}
IEnumerator Bar(System.Action<bool> callback)
{
    yield return null;
    callback(true);
}

https://discussions.unity.com/t/how-do-i-return-a-value-from-a-coroutine/6438/5

with argument

void Foo()
{
    StartCoroutine(Bar("1",(bool myReturnValue) => {
        if(myReturnValue) { ... }
    });
}
IEnumerator Bar(string msg, System.Action<bool> callback)
{
    yield return null;
    callback(msg=="1");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment