Looking at Unity made me understand the point of C++ coroutines
a day ago
- #Game Development
- #Coroutines
- #C++
- C++ coroutines have been available for 6 years but are rarely used in production due to their low-level nature and lack of concrete examples.
- Unity's use of C# coroutines for spawning effects and ephemeral behaviors provides a practical example of coroutine utility.
- Coroutines simplify complex state machines into readable functions, as demonstrated by the 'TimeWarp' example.
- C++23's <generator> makes yielding from coroutines easier, but handling co_await remains complex and project-specific.
- A simple Unity-style coroutine executor in C++ can be implemented with less than 100 lines of code, offering a practical alternative to complex state machines.
- Coroutines can be adapted to return values (e.g., renderable objects), enabling parallel execution and efficient effect systems.