Enabling InputAction from non main thread (e.g. coroutine) breaks InputAction (0.2.1-preview)
Version:
- 0.2.1-preview (via unity package manager).
In the main menu of my project i am switching different menu panels via an animation, e.g.:
StartCoroutine(PanelAnimation(toLeft, true, _activePanel));
In this animation coroutine i do at some point
panel.SetActive(false) or panel.SetActive(true)
which triggers my OnEnable/OnDisable methods where i do
void OnEnable() {
inputAction.Enable();
}
void OnDisable() {
inputAction.Disable();
}
...like in the tutorials.
BUT there is a problem with enabling the InputAction when coming from a Coroutine (non main thread).
Solution for me:
void OnEnable() {
MainThreadExecuter.Execute(() => inputAction.Enable());
}
...which enables the input action on the main thread (in the next Update() of another script).
Hope i could help (first time github posting) :)
I cannot repro this on my end. @acidwarrior27 is this still the case for you on 0.2.6-preview?
@acidwarrior27 if this is still an issue, can you upload the C# scripts related to the error? Thanks!
I updated to:
- Unity 2019.1.0f2 (official)
- InputSystem 0.2.8 preview
and everything seems fine now!
there is a problem with enabling the InputAction when coming from a Coroutine (non main thread)
Note that the input system API follows the same model as other APIs in UnityEngine, only methods explicitly marked as [ThreadSafe] are safe to be called from a thread other than the main thread.
In the context of the new DOTS/ECS stuff, there will be new APIs that break with this model.