r/cpp • u/mropert • Mar 20 '26
Looking at Unity finally made me understand the point of C++ coroutines · Mathieu Ropert
https://mropert.github.io/2026/03/20/unity_cpp_coroutines/
88
Upvotes
r/cpp • u/mropert • Mar 20 '26
View all comments
14
u/SuperV1234 https://romeo.training | C++ Mentoring & Consulting Mar 20 '26
One big issue is that the state of C++ coroutines is completely opaque -- that makes it impossible to serialize/deserialize them to memory/disk.
Therefore, they're unfortunately not suitable for game logic if you value the ability of deterministically saving/loading their state, which is important for persistance, networking, testing, and so on.
This is yet another example of where the design of Core Coroutines would have been superior.
If you want to both (1) coroutine-like code and (2) serialization/deserialization you need to resort to macros. Here's an example of how you can do that (unpolished, just an experiment): https://gcc.godbolt.org/z/9s9ssze8P