Skip to content

Instantly share code, notes, and snippets.

@hon454
Last active October 2, 2023 19:06
Show Gist options
  • Save hon454/b639d1a95287f78b29d261d2f81b8968 to your computer and use it in GitHub Desktop.
Save hon454/b639d1a95287f78b29d261d2f81b8968 to your computer and use it in GitHub Desktop.
[SteamVR][Unity] Tracker tracking without HMD
using UnityEngine;
using Valve.VR;
public class SteamVR_TrackingWithoutHMD : MonoBehaviour
{
private CVRSystem _vrSystem;
private TrackedDevicePose_t[] _poses = new TrackedDevicePose_t[OpenVR.k_unMaxTrackedDeviceCount];
// initialize
void Awake()
{
var err = EVRInitError.None;
_vrSystem = OpenVR.Init(ref err, EVRApplicationType.VRApplication_Other);
if (err != EVRInitError.None)
{
// handle init error
}
}
// get tracked device poses
void Update()
{
// get the poses of all tracked devices
_vrSystem.GetDeviceToAbsoluteTrackingPose(ETrackingUniverseOrigin.TrackingUniverseStanding, 0.0f, _poses);
// send the poses to SteamVR_TrackedObject components
SteamVR_Events.NewPoses.Send(_poses);
}
// shutdown
void OnDestroy()
{
OpenVR.Shutdown();
}
}
@sergiobd
Copy link

@Kaonuri, is this code MIT Licensed? If so, would you mind adding a license for it? e.g. https://opensource.org/licenses/MIT

@bonzomi
Copy link

bonzomi commented Oct 2, 2023

Is there any way to do this on Unity 2021 or later? The openvr_api.dll is not included in the folder structure
Edit: Solved. For anyone facing the same problem, the openvr_api.dll is located under your Unity project folder instead of the Unity Editor installation folder. The path should look something like this "YourProject\Library\PackageCache\com.valvesoftware.unity.openvr...\Runtime\x64\openvr_api.dll"
Replace the 'x64' to 'x86' if your build settings are set to Intel 32-bit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment