InputSystem icon indicating copy to clipboard operation
InputSystem copied to clipboard

Enabling InputAction from non main thread (e.g. coroutine) breaks InputAction (0.2.1-preview)

Open acidwarrior27 opened this issue 7 years ago • 4 comments

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) :)

acidwarrior27 avatar Apr 05 '19 15:04 acidwarrior27

I cannot repro this on my end. @acidwarrior27 is this still the case for you on 0.2.6-preview?

JiaUnity avatar Apr 12 '19 23:04 JiaUnity

@acidwarrior27 if this is still an issue, can you upload the C# scripts related to the error? Thanks!

JiaUnity avatar Apr 19 '19 23:04 JiaUnity

I updated to:

  • Unity 2019.1.0f2 (official)
  • InputSystem 0.2.8 preview

and everything seems fine now!

acidwarrior27 avatar Apr 25 '19 15:04 acidwarrior27

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.

Rene-Damm avatar Apr 25 '19 15:04 Rene-Damm