microsoft / MixedRealityToolkit-Unity

This repository is for the legacy Mixed Reality Toolkit (MRTK) v2. For the latest version of the MRTK please visit https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity
https://aka.ms/mrtkdocs
MIT License
6k stars 2.12k forks source link

Xbox Controller implementation not working with HL2 & MRTK on Build #10040

Closed wlewis55 closed 2 years ago

wlewis55 commented 3 years ago

A few of my colleagues (@lstearns86) and I have been attempting to get Xbox Controllers working with the newest updates to MRTK in Unity 2020. We have had this working on projects in the past (2.6.1), but unfortunately have had no luck with MRTK 2.7. As per #9931 and the updates found in 2.7.1, the Xbox controller works in the Unity Editor, but not in the HL2 after a build.

To reproduce

Steps to reproduce the behavior:

  1. Set up MRTK in a Unity project.
  2. Create new profiles for the InputSystem, InputActions, ControllerMapping, and define controller definitions for Xbox Controller.
  3. Create a new script to enable functions for the controller, and create a function to manipulate an on-screen object (so you can see it after the build). Here is an example of our setup:

Note: We have also tried inheriting from the BaseInputHandler instead of the InputSystemGlobalHandlerListener

using UnityEngine;
using Microsoft.MixedReality.Toolkit;
using Microsoft.MixedReality.Toolkit.Input;

public class Input_MRTK_Implementation : 
  InputSystemGlobalHandlerListener, IMixedRealityInputHandler {

  [Header("MRTK Input Actions")]
  [SerializeField] private MixedRealityInputAction Start_Button;
  [SerializeField] private MixedRealityInputAction View_Button;
  [SerializeField] private MixedRealityInputAction A_Button;
  [SerializeField] private MixedRealityInputAction B_Button;
  [SerializeField] private MixedRealityInputAction Y_Button;
  [SerializeField] private MixedRealityInputAction X_Button;
  [SerializeField] private MixedRealityInputAction Left_Bumper;
  [SerializeField] private MixedRealityInputAction Right_Bumper;

  [SerializeField] private bool _start;
  [SerializeField] private bool _view;
  [SerializeField] private bool _a;
  [SerializeField] private bool _b;
  [SerializeField] private bool _y;
  [SerializeField] private bool _x;
  [SerializeField] private bool _lb;
  [SerializeField] private bool _lb;
  [SerializeField] private bool _rb;

#region On Input Up/Down
  public void OnInputUp(InputEventData eventData){
    if(eventData.MixedRealityInputAction == Start_Button) _start = false;
      if(eventData.MixedRealityInputAction == View_Button) _view = false;
      if(eventData.MixedRealityInputAction == A_Button) _a = false;
      if(eventData.MixedRealityInputAction == B_Button) _b = false;
      if(eventData.MixedRealityInputAction == Y_Button) _y = false;
      if(eventData.MixedRealityInputAction == X_Button) _x = false;
      if(eventData.MixedRealityInputAction == Left_Bumper) _lb = false;
      if(eventData.MixedRealityInputAction == Right_Bumper) _rb =  false;
  }

  public void OnInputDown(InputEventData eventData){
      if(eventData.MixedRealityInputAction == Start_Button) _start = true;
      if(eventData.MixedRealityInputAction == View_Button) _view = true;
      if(eventData.MixedRealityInputAction == A_Button) _a = true;
      if(eventData.MixedRealityInputAction == B_Button) _b = true;
      if(eventData.MixedRealityInputAction == Y_Button) _y = true;
      if(eventData.MixedRealityInputAction == X_Button) _x = true;
      if(eventData.MixedRealityInputAction == Left_Bumper) _lb = true;
      if(eventData.MixedRealityInputAction == Right_Bumper) _rb = true; 
  }
#endregion

#region Handlers
  protected override void RegisterHandlers(){
    CoreServices.InputSystem.RegisterHandler< IMixedRealityInputHandler >(this);
  }

  protected override void UnregisterHandlers(){

  } 
#endregion
}
  1. Map your MixedRealityInputAction 's to the Input Actions defined in the Controller Definitions section of MRTK.

image

  1. Test in the Unity Editor. If the Xbox Controller does not respond, you need to make sure the UnityJoystickManager Provider is included in Input Data Providers.
  2. Once you can see the Xbox Controller works with your setup, build to the HL2!
  3. Before you start the application, connect your Xbox Controller to your HL2 over Bluetooth.
  4. Open the application and test the functionality of the controller.

Expected behavior

The Xbox controller should work the same way as it does in the editor.

Your setup

Target platform

Additional context

keveleigh commented 3 years ago

Can you please let me know which Windows version you have on your HoloLens? We're currently investigating a potential issue in certain Windows versions with Xbox controller not coming through properly.

wlewis55 commented 3 years ago

@keveleigh My HL2 is running:

lstearns86 commented 3 years ago

I'm having this issue as well, but I'm running OS Build 20348.1007

keveleigh commented 3 years ago

Yep, those builds both look solidly in the range where I'd expect this. I'll mark this issue as External and will follow-up here when a fix ships!

wlewis55 commented 3 years ago

Thanks!

crunkett09 commented 3 years ago

I'm also running into this issue.

lstearns86 commented 3 years ago

@keveleigh Is there a workaround for this issue, or an estimate on when it will be fixed? Or can you provide a specific version of Windows (and/or MRTK) that we should roll back to so that the Xbox controllers will work again?

keveleigh commented 3 years ago

This should be fixed in Windows 20348.1405 or newer (it should be in one of the Insider Preview rings). You may need to unpair/repair your Xbox controller to your device.

keveleigh commented 3 years ago

If you instead want to roll back, you can roll back to any 20H2 builds. This issue was only present on 21H1 builds.