Last active
December 11, 2025 15:16
-
-
Save unitycoder/0a89f366983e457ab125904b301c3f4c to your computer and use it in GitHub Desktop.
Unity Coroutine with Callback Return Value and method parameter, or call coroutine from another coroutine without StartCoroutine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| IEnumerator Parent() | |
| { | |
| Debug.Log("Parent: before child"); | |
| yield return ChildCoroutine(); | |
| Debug.Log("Parent: after child"); | |
| } | |
| IEnumerator ChildCoroutine() | |
| { | |
| Debug.Log("Child: step 1"); | |
| yield return new WaitForSeconds(1f); | |
| Debug.Log("Child: step 2"); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // caller | |
| StartCoroutine(DoSomething((success) => | |
| { | |
| }); | |
| int myarg=1; | |
| StartCoroutine(DoSomething(myarg, (Bool success) => | |
| { | |
| if (success) | |
| { | |
| Debug.Log("Success"); | |
| } | |
| else | |
| { | |
| Debug.Log("Failed"); | |
| } | |
| } | |
| })); | |
| // coroutine | |
| IEnumerator DoSomething(int arg, Action<bool> callback) | |
| { | |
| if (arg==0) | |
| { | |
| callback(false); | |
| } | |
| callback(true); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment