Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

InputSystem 1.2.0 not calling event handlers in playmode tests

Discussion in 'Input System' started by xealgo, Dec 11, 2021.

  1. xealgo

    xealgo

    Joined:
    Dec 30, 2012
    Posts:
    12
    My play mode tests have been passing without an issue until I updated the InputSystem to version 1.2.0. I've verified keys are getting pressed via:

    Press(keyboard.dKey);
    Code (CSharp):
    1. Press(keyboard.dKey);
    2. ...
    3. Assert.True(keyboard.dKey.isPressed);
    And then in my controller class, I'm adding events like so:
    Code (CSharp):
    1. Move.started += HandleMoveInput;
    (also have performed and canceled bound)

    However,
    Code (CSharp):
    1. HandleMoveInput
    is now not getting called during play mode tests. Everything works perfect without an issue when running then game in the editor. I've even rolled back to the previous version to see if I somehow broke something, but my tests all passed.

    I've read through the docs for version 1.2.0 and Googled for the last hour. I'm sure it's probably something simple I'm missing. Note that my test code only differs from the docs in that I'm using [UnityTest] vs [Test].
     
  2. xealgo

    xealgo

    Joined:
    Dec 30, 2012
    Posts:
    12
    Hate to bump this, but does anyone have any ideas?
     
  3. xealgo

    xealgo

    Joined:
    Dec 30, 2012
    Posts:
    12
    Never mind. I figured out the issue. It had to do with bootstrapping in the test. I'm using mirror and loading up a network scene, so my bootstrapping is a bit different. I found that `Setup` was getting called after I was binding the input handlers, so I moved some stuff around:

    Code (CSharp):
    1.  
    2. [UnitySetUp]
    3. public IEnumerator Bootstrap() {
    4.        // scene load stuff
    5.       yield return null;
    6. }
    7.  
    8. public override void Setup() {
    9.         base.Setup();
    10.  
    11.         mouse = InputSystem.AddDevice<Mouse>();
    12.         keyboard = InputSystem.AddDevice<Keyboard>();
    13.         ...
    14.         controller.BindInputs();
    15. }
    16.  
     
    PutridEx likes this.