You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 23, 2020. It is now read-only.
Add a GameObject to you scene and add the UnityMainThreadDispatcher script to it. Make sure that this GameObject is in your scene.
//Getting an instance with static methodIMainThreadDispatcherdispatcher=UnityMainThreadDispatcherExtensions.Instance;dispatcher.Invoke(()=>Debug.Log("Hello 1"));awaitdispatcher.InvokeAsync(()=>Debug.Log("Hello 2"))Buttonbutton=awaitdispatcher.InvokeAsync(()=>GameObject.FindObjectOfType<Button>()))
Calling the dispatcher is thread safe
Gotchas
If you call UnityMainThreadDispatcherExtensions.Instance before the the GameObject containing it is instantiated you will get an exception.
If you call UnityMainThreadDispatcherExtensions.Instance for the first time from a thread other than the main unity thread, you will get an exception.
If there are multiple instances in you scene, then when calling UnityMainThreadDispatcherExtensions.Instance it will cache the first it finds. Preferably you only want one instance of it in your application, having multiple does not provide any performance benefit