Closed mauricioribeiro closed 3 years ago
We used this nice plugin on the asset store for dispatching to the MainThread: Task Parallel
Then in that Bind action you would do this:
UnityTask.RunOnUIThread(() => {
_myGameObject.GetComponent<Player>().DoSomething();
});
If you don't want to purchase that plugin, basically they are adding this action to a threadsafe queue which gets dequeued and invoked inside a MonoBehaviour Update() event.
Thank you @twomedia. After some time, I managed to solve this by setting a boolean flag variable (like IsEventTriggered
) on async Bind
method to avoid get component on it.
So, in the async scope, I only set this flag to true instead call component DoSomething()
and then in my not syncUpdate
scope I verify this flag. If it's true, I finally call the componentDoSomething()
.
That was a workaround, but solved my problem. I think what I did is somehow similar to the plugin you recommended. Anyway, I will check it out :)
Hi guys,
I have the following code in my PusherManager:
Basically, I'm just trying to call a method from an attached
GameObject
in my PusherManager. But, since the code insideBind
method is async and it's using a different thread, the code throws this error:I made some research and I think Unity blocks any
GetComponent
call inside parallel threads. Does anybody have any clue about how to solve this?