Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question UnpairedDeviceActivity errors occur when trying to test

Discussion in 'Input System' started by Dowlgrett, Sep 2, 2023.

  1. Dowlgrett

    Dowlgrett

    Joined:
    Feb 27, 2022
    Posts:
    6
    I'm trying to get into TDD, just messing around and trying to make a simple test to pass, here it is:

    Code (CSharp):
    1. public class PlayModeTests : InputTestFixture
    2. {
    3.    public override void Setup()
    4.    {
    5.        base.Setup();
    6.        SceneManager.LoadScene("Assets/Scenes/Main.unity");
    7.    }
    8.  
    9.    [UnityTest]
    10.    public IEnumerator Clicking_Card_Selects_It()
    11.    {
    12.        var handPanel = GameObject.Find("HandPanel");
    13.        var card = handPanel.transform.GetChild(0);
    14.  
    15.        var mouse = InputSystem.AddDevice<Mouse>();
    16.  
    17.        Camera camera = GameObject.Find("Main Camera").GetComponent<Camera>();
    18.        Vector3 screenPos = camera.WorldToScreenPoint(card.transform.position);
    19.        Set(mouse.position, screenPos);
    20.        Click(mouse.leftButton);
    21.  
    22.        yield return new WaitForSeconds(0.1f);
    23.  
    24.        Assert.That(EventSystem.current.currentSelectedGameObject, Is.EqualTo(card.gameObject));
    25.    }
    26. }
    And the test doesn't pass: the expected value is Card, but was null. And in the console it gives me this monstrosity:

    ArgumentOutOfRangeException: Cannot be negative
    Parameter name: value
    UnityEngine.InputSystem.Users.InputUser.set_listenForUnpairedDeviceActivity (System.Int32 value) (at Library/PackageCache/com.unity.inputsystem@1.5.1/InputSystem/Plugins/Users/InputUser.cs:412)
    UnityEngine.InputSystem.PlayerInput.StopListeningForUnpairedDeviceActivity () (at Library/PackageCache/com.unity.inputsystem@1.5.1/InputSystem/Plugins/PlayerInput/PlayerInput.cs:1685)
    UnityEngine.InputSystem.PlayerInput.OnDisable () (at Library/PackageCache/com.unity.inputsystem@1.5.1/InputSystem/Plugins/PlayerInput/PlayerInput.cs:1720)

    Event system is in the scene: check
    Assembly definition has references to UnityEngine.InputSystem and UnityEngine.InputSystem.TestFramework: check

    What am I missing?