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 How to simulate VR input in automatic testing?

Discussion in 'XR Interaction Toolkit and Input' started by edwon, Sep 24, 2022.

  1. edwon

    edwon

    Joined:
    Apr 24, 2011
    Posts:
    265
    How do you simulate VR input from code in automatic tests using Unity Test Framework?

    I need to automate testing of the VR player grabbing things, dropping them, etc...

    Looked through a lot of docs and tutorials to try to find a path to do this, found nothing. Tried a lot of things myself, nothing works.

    I'm using the new Unity Input Package and all the standard Unity VR packages/plugins etc... along with XR Interaction Toolkit
     
  2. VRDave_Unity

    VRDave_Unity

    Unity Technologies

    Joined:
    Nov 19, 2021
    Posts:
    260
    Hey @edwon,
    If you are looking for some examples of how to do some of this type of test automation, XRI actually has a lot of automated testing you can use as a reference. You will need to add it to the testables area of your project manifest like so:
    Code (JavaScript):
    1. {
    2.   "dependencies": {
    3.      ... existing dependencies ...
    4.   },
    5.   "testables": [
    6.     "com.unity.inputsystem",
    7.     "com.unity.xr.interaction.toolkit"
    8.   ]
    9. }
    We have an internal dependency on the Input System for our test fixture, which is why you will need both. Once you have that inserted into your manifest, you'll want to open up the Test Runner
    (Window > General > TestRunner)
    window to see the list of tests:
    upload_2022-9-29_13-56-24.png
    The actual C# scripts responsible for these tests can be accessed inside the project by expanding the Packages area in the Project window and navigating to
    XR Interaction Toolkit > Tests > Runtime
    :
    upload_2022-9-29_13-57-52.png
    Hopefully this helps you get started in building your own tests. Feel free to reach out if you have more questions.
     
  3. edwon

    edwon

    Joined:
    Apr 24, 2011
    Posts:
    265
    Ok thanks for the instruction! I saw this mesage and it was like Christmas.

    So digging through the test code, I found this:

    Code (CSharp):
    1.  
    2. var controllerRecorder = TestUtilities.CreateControllerRecorder(controller, (recording) =>
    3. {
    4.     recording.AddRecordingFrameNonAlloc(new XRControllerState(0.0f, Vector3.zero, Quaternion.identity, InputTrackingState.All, true, false, false));
    5.     recording.AddRecordingFrameNonAlloc(new XRControllerState(float.MaxValue, Vector3.zero, Quaternion.identity, InputTrackingState.All,
    6.                     true, false, false));
    7. });
    8. controllerRecorder.isPlaying = true;
    So I'm guessing this is how you do it? basically just add an XRControllerRecorder and then add some frames and start it playing

    still haven't found how to move the head around though
     
  4. VRDave_Unity

    VRDave_Unity

    Unity Technologies

    Joined:
    Nov 19, 2021
    Posts:
    260
    Hey @edwon
    You could likely just move the XR Origin in a similar manner, since that would bring the child objects with it. Otherwise you can find and move the main camera in whatever test setup you are using.
     
  5. edwon

    edwon

    Joined:
    Apr 24, 2011
    Posts:
    265
    The main issue here is input, such as buttons on the hand controller, and also the hand positions, I already tried moving the camera and origin and hands via direct transform manipulation.