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.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR;
public class HandPresence : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
List<InputDevice> devices = new List<InputDevice>();
InputDeviceCharacteristics rightControllerCharacteristics = InputDeviceCharacteristics.Right | InputDeviceCharacteristics.Controller;
InputDevices.GetDevicesWithCharacteristics(rightControllerCharacteristics, devices);
foreach (var item in devices)
{
Debug.Log(item.name + item.characteristics);
}
}
// Update is called once per frame
void Update()
{
}
}
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!
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.
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.
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.
I’m following the same tutorial and having the same issue, all its simply trying to do is print to console what items are connected to the game (being the VR controllers and headset) and nothing else. I can’t figure out why it won’t print, when I have identical code.
When you’re starting VR in the Unity Editor there frequently won’t be any devices connected in frame 0, so you need to wait a bit for VR to actually initialize.
I just tried this code out and it works:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR;
public class HandPresence : MonoBehaviour
{
// Start is called before the first frame update
IEnumerator Start() {
List<InputDevice> devices = new List<InputDevice>();
InputDeviceCharacteristics rightControllerCharacteristics = InputDeviceCharacteristics.Right | InputDeviceCharacteristics.Controller;
while (devices.Count == 0) {
// check for devices every frame until you find one.
yield return null;
InputDevices.GetDevicesWithCharacteristics(rightControllerCharacteristics, devices);
}
foreach (var item in devices)
{
Debug.Log(item.name + item.characteristics);
}
}
}