Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Input test-framework v1.3 Set control multiple times in a single test?

Discussion in 'Input System' started by Sangemdoko, Jan 31, 2023.

  1. Sangemdoko

    Sangemdoko

    Joined:
    Dec 15, 2013
    Posts:
    220
    Hi,

    I'm having an issue with the input test-framework:
    https://docs.unity3d.com/Packages/com.unity.inputsystem@1.3/manual/Testing.html

    I'm trying to do a very simple test of moving left then right (vice/versa)

    But for some reason once the control is set, it can't be changed. I tried both Set(...) and Move(...) both give me the same result.

    Note: I know the issue isn't my code because it works when I test manually. Also the tests below are very simple but I need this to work to do some more complex testing.

    Code (CSharp):
    1.  
    2. public void SetMoveInput(int playerIndex, Vector2 dir)
    3. {
    4.     var gamepad = m_InputDevices[playerIndex];
    5.     //m_InputFixture.Move(gamepad.leftStick, dir);
    6.     m_InputFixture.Set(gamepad.leftStick,dir);
    7. }
    8.  
    9. [UnityTest]
    10. public IEnumerator Move_Left_Right()
    11. {
    12.     var characterIndex = 0;
    13.     var character = GameCommands.GetPlayer(characterIndex);
    14.     var previousPos = character.transform.position;
    15.  
    16.     SetMoveInput(characterIndex, new Vector2(-1,0));
    17.     yield return new WaitForSeconds(1f);
    18.  
    19.     Assert.Greater(previousPos.x, character.transform.position.x);
    20.  
    21.     SetMoveInput(characterIndex, new Vector2(1,0));
    22.  
    23.     yield return new WaitForSeconds(2f);
    24.  
    25.     Assert.Greater(character.transform.position.x, previousPos.x);
    26. }
    27. [UnityTest]
    28. public IEnumerator Move_Right_Left()
    29. {
    30.     var characterIndex = 0;
    31.     var character = GameCommands.GetPlayer(characterIndex);
    32.     var previousPos = character.transform.position;
    33.  
    34.     SetMoveInput(characterIndex, new Vector2(1,0));
    35.     yield return new WaitForSeconds(1f);
    36.  
    37.     Assert.Greater(character.transform.position.x, previousPos.x);
    38.  
    39.     SetMoveInput(characterIndex, new Vector2(-1,0));
    40.  
    41.     yield return new WaitForSeconds(2f);
    42.  
    43.     Assert.Greater(previousPos.x, character.transform.position.x);
    44.  


    Is this a bug with version 1.3 or am I doing something wrong? I can't find any examples of a control being set multiple times in a single test.
    I'd like to avoid updating now since I'm close to releasing my game, I'm writing those test to help me solve some edgecases.
     
  2. Sangemdoko

    Sangemdoko

    Joined:
    Dec 15, 2013
    Posts:
    220
    Well just out of curiosity I tried setting the control to zero before setting my new value and it seems to magically fix it

    Code (CSharp):
    1. public void SetMoveInput(int playerIndex, Vector2 dir)
    2. {
    3.     var gamepad = m_InputDevices[playerIndex];
    4.    
    5.     //Added this extra line, seems to do the trick.
    6.     m_InputFixture.Set(gamepad.leftStick,Vector2.zero);
    7.    
    8.     m_InputFixture.Set(gamepad.leftStick,dir);
    9. }
    So my guess is that this really is a bug