jacksondunstan / UnityNativeScripting

Unity Scripting in C++

Home Page:https://jacksondunstan.com/articles/3938

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to do Coroutine in c++

sekkit opened this issue · comments

As the title indicates, is it possible to enable coroutine in c++.

Yes, but with caveats. You can certainly expose MonoBehaviour.StartCoroutine, call it with an IEnumerator, and use its returned Coroutine. You can even create your own base class implementing IEnumerator in the same way you create a MonoBehaviour derivative. That class' Current and MoveNext can be written in C++ just like how you'd write MonoBehaviour message handlers like Start or OnDestroy in C++. However, that's not as natural a way to write a coroutine as you'd usually do in C#. That's because there's currently no support for iterator functions (i.e. those that yield) in the bindings or in C++ itself. This may change if coroutines make it into C++20.