Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Switching between single und dual controller input using SteamVR Unity plugin's Player prefab

Discussion in 'AR/VR (XR) Discussion' started by matazematratze, Sep 6, 2018.

  1. matazematratze

    matazematratze

    Joined:
    May 3, 2015
    Posts:
    9
    I keep running into a Null reference problem with my InputManager script. The basic idea is, I want to detect wether both Vive controllers or only one controller is connected. Based on that I'll initiate the single controller controls or dual controller controls. I'm using the Player prefab from the SteamVR Unity plugin.

    The thing is, I can't find another way to check for that than:

    Code (CSharp):
    1. if (!Player.instance.rightHand.controller.connected | !Player.instance.leftHand.controller.connected){
    2. //switch to single controller controls
    3. }
    And since that throws a Null exception if one of the controllers is non-existent, the part in the brackets is never reached.

    Has somebody found an elegant way to solve that?