[HOWTO] How To: Start Coroutine From Lua
Posted: Sat Jul 31, 2021 8:06 am
To start a C# coroutine from Lua, register a non-coroutine method with Lua. Example:
Note: Using this technique, Lua doesn't report back the status of the coroutine. If you need to wait for the coroutine to finish, consider using a custom sequencer command instead. Example:
Code: Select all
Lua.RegisterFunction("StartMyCoroutine", this, SymbolExtensions.GetMethodInfo(() => StartMyCoroutine()));
...
public void StartMyCoroutine()
{
StartCoroutine(MyCoroutine());
}
IEnumerator MyCoroutine()
{
...
}
Code: Select all
public class SequencerCommandMyCoroutine : SequencerCommand
{
IEnumerator Start()
{
... // (your coroutine code here)
Stop(); // Always call stop when command is done.
}
}