Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Help Wanted Problem with VR Controller Input

Discussion in 'VR' started by kingjohnc19, Jun 28, 2020.

  1. kingjohnc19

    kingjohnc19

    Joined:
    Apr 19, 2018
    Posts:
    3
    I'm following this tutorial to create a VR game:


    I got up to 5:56 in the video. My code is identical to the code in the video, but I'll include it just in case.
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.XR;
    5.  
    6. public class HandPresence : MonoBehaviour
    7. {
    8.     // Start is called before the first frame update
    9.     void Start()
    10.     {
    11.         List<InputDevice> devices = new List<InputDevice>();
    12.         InputDeviceCharacteristics rightControllerCharacteristics = InputDeviceCharacteristics.Right | InputDeviceCharacteristics.Controller;
    13.         InputDevices.GetDevicesWithCharacteristics(rightControllerCharacteristics, devices);
    14.  
    15.         foreach (var item in devices)
    16.         {
    17.             Debug.Log(item.name + item.characteristics);
    18.         }
    19.     }
    20.  
    21.     // Update is called once per frame
    22.     void Update()
    23.     {
    24.  
    25.     }
    26. }
    27.  
    When I save the code and run the game in Unity, nothing shows up in the console. Did I do something wrong? I'm using a Windows Mixed Reality headset. Thank you in advance!
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,821
    Is the code running at all? Easiest way to be sure would be to add a Debug.Log outside the foreach loop. Something like Debug.Log("Yep, HandPresence.Start is actually running") would be enough to test your assumption that this code is running.

    If it's not running, then it's probably just that you didn't attach this script to an active object in the scene.
     
  3. kingjohnc19

    kingjohnc19

    Joined:
    Apr 19, 2018
    Posts:
    3
    I've already tested this out before and It's safe to say that the code is actually running. I'm starting to suspect that my headset just doesn't work very well with the Unity XR Toolkit? I'm not really sure about anything, because this is my first time messing with VR.
     
  4. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,821
    I dunno. I can tell you that our VR app does work with WMR. Somewhere there is an assumption you are making that is not true; you just need to track that down (and your current script is not very helpful with that, unless perhaps you're stepping through it in the debugger). Debug.Log everything you can think of until you find that faulty assumption.
     
  5. kingjohnc19

    kingjohnc19

    Joined:
    Apr 19, 2018
    Posts:
    3
    Thank you for the help!
     
  6. cyenketswamy

    cyenketswamy

    Joined:
    Jul 24, 2015
    Posts:
    37
    Your code looks incomplete.
     
unityunity