Search Unity

How to block all player input during Play Mode tests?

Discussion in 'Testing & Automation' started by huulong, Jun 5, 2021.

  1. huulong

    huulong

    Joined:
    Jul 1, 2013
    Posts:
    224
    I noticed that unlike the Play Mode tests of the early times of the Test Runner (when you had to install the Test Runner package from the asset store, and everything was based on scenes and objects that would enable/disable themselves depending on the current test), player input is not blocked during the Play Mode tests. This allows the user to mess up with the tests, which can be useful when you want to debug a certain thing, but the rest of the time just makes it undeterministic and error-prone.

    Is there any way to block player input with a single function at the start of the test? Or should I manually disable on Player Input and Event System components to prevent both character control and menu navigation while I let my test script run?
     
  2. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,658
    I think it's going to depend on which input system you're using. With the new input system, there's APIs for disabling devices, or you could set the entire system into 'manual' update mode (which means it shouldn't process any input unless you explicitly call Update).
     
  3. huulong

    huulong

    Joined:
    Jul 1, 2013
    Posts:
    224
    OK, I'm using the new Input System. I didn't a particular method on the InputDevice, but it may be on a different level. I'll ask again on the Input System forum if I don't find it.
     
    superpig likes this.
  4. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,658
  5. huulong

    huulong

    Joined:
    Jul 1, 2013
    Posts:
    224
    The UpdateMode -> Manual may do it. If I disable device, I fear it will also disable my simulation.
    I'll try it next time I run PlayMode tests.