Requires Unity 2019+
https://github.com/gustavopsantos/unitymainthreaddispatcher.git?path=/Assets/UnityMainThreadDispatcher/#1.0.0
- Download the .unitypackage from releases page.
- Import UnityMainThreadDispatcher.X.X.X.unitypackage
After downloading or installing by package manager, thats it, since we rely on low level player loop system, theres no need for creating a gameobject in order to hook MonoBehaviour update method
UnityMainThreadDispatcher.Dispatcher.Enqueue(() => Debug.Log("This is happening on unity main thread"));