Hi! Is it possible in Unity to get the current amount of remaining battery percentage per left/ right VR controller? (I see there’s SystemInfo.batteryLevel but that presumably relates to e.g. a mobile device’s battery.) Thanks!
Even though this question was asked a long time ago, I’ll still provide the answer, in case anyone else is searching for it. In short: Yes, you can.
It is just not made “readily available”, it’s hidden in the API
You can use the ETrackedDeviceProperty
for each of the controller or HMD, which describes the different information that is tracked for each device. The enum property you’d be looking for is called Prop_DeviceBatteryPercentage_Float
.
You can query this property by using
ETrackedPropertyError err = new ETrackedPropertyError();
float f = OpenVR.System.GetFloatTrackedDeviceProperty((uint)trackedObj.index,ETrackedDeviceProperty.Prop_DeviceBatteryPercentage_Float, ref err);
if (err == ETrackedPropertyError.TrackedProp_Success) {
Debug.Log("Battery level: " + f);
}else{
Debug.LogError("Cannot read batterylevel: " + err.ToString());
}
where trackedObj
is your SteamVR_TrackedObject
, representing a controller. The returned value will range between 0 and 1.