Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question How to get Oculus Quest 2 battery levels?

Discussion in 'VR' started by PascalTheDog, Jun 15, 2022.

  1. PascalTheDog

    PascalTheDog

    Joined:
    Mar 16, 2015
    Posts:
    86
    Hey,

    I'm working on a multiplayer VR game for the Oculus Quest 2 and I'd need access to the battery level of each device independently (headset, left controller, right controller).

    I searched it up but couldn't find any definitive answer online. Some mention using OVRManager.batteryLevel, but I always get 0 as a return value in both Editor runtime and headset builds.

    Visual Studio flags that field as obsolete anyway and suggests using Unity's built-in SystemInfo.batteryLevel instead, but that doesn't work either — now I always get -1 in-Editor (i.e. the headset is not recognized) and 1 in-build regardless of actual battery level.

    Besides, the value is a single float so which battery are we even talking about here? The headset's? I'd also need to know the level of that of both controllers.

    Assistance would be greatly appreciated. Cheers!
     
  2. PascalTheDog

    PascalTheDog

    Joined:
    Mar 16, 2015
    Posts:
    86
    Well... Scratch that, now SystemInfo.batteryLevel *does* return the right value (in-build). I'm not quite sure what might have brought upon that change, but it seems to be working consistently now. Weird.

    Still, the thread remains relevant because I haven't found a way to get the battery level of controllers.
     
  3. glenneroo

    glenneroo

    Joined:
    Oct 27, 2016
    Posts:
    228
    OVRInput has a static method
    GetControllerBatteryPercentRemaining() which returns the battery level for controllers.
     
  4. PascalTheDog

    PascalTheDog

    Joined:
    Mar 16, 2015
    Posts:
    86
    Thank you for your response! Sadly, I always get 0% as a return value — both in-Editor and in-build. I've tried using different values for the OVRInput.Controller argument (default i.e. Active, LHand/RHand, LTouch/RTouch, Gamepad, etc) to no avail.

    I don't understand why relevant documentation is so sparse.
     
  5. glenneroo

    glenneroo

    Joined:
    Oct 27, 2016
    Posts:
    228
    Sorry I really should have tested it myself before commenting - getting the same results here, 0 regardless of argument :(

    Documentation is probably sparse because Ocul...err, Face...err Meta is "moving fast and breaking things" with every major API update. I've found so many TODO comments, empty Update() loops (a big no-no in Unity much less VR), creation of nameless GameObjects which appear in scenes as "Game Object" (it's literally an argument when you create a GameObject), hastily written unfinished code that I try to clean-up when I have to deal with it, but then I get to merge my changes into with every monthly API update... I wish there was a way to submit bugfix requests in their API like is (usually) possible with other Assets from the store. They keep adding code but it feels like nobody is testing it. All those billions being spent yet they seem to have forgotten to hire someone to do internal code reviews.
     
  6. PascalTheDog

    PascalTheDog

    Joined:
    Mar 16, 2015
    Posts:
    86
    Simply getting the headset's serial number is also a nightmare. From what I understand, this used to work fine:
    AndroidJavaObject jo = new("android.os.Build");
    string serialNumber = jo.GetStatic<string>("SERIAL");

    but apparently a somewhat recent update made it so now that only returns "unknown". The code is still there, but effectively unusable.

    I can understand experimental features being unreliable or poorly documented, but this is just getting a string or float of some of an headset's most basic settings — this really shouldn't be a time-wasting issue.

    Anyway, thank you for your advice and explanation.
     
  7. vrl4demo

    vrl4demo

    Joined:
    May 11, 2022
    Posts:
    1
    Using serial numbers is seem no longer supported as of Android 10
    You can check HMD's battery by:
    float level = SystemInfo.batteryLevel * 100;
    BatteryStatus status = SystemInfo.batteryStatus;

    And check controller's battery by adb cmd:
    adb logcat | findstr /C:"serial" /C:"handedness" /C:"battery state"
     
  8. Oliver2222

    Oliver2222

    Joined:
    Aug 17, 2022
    Posts:
    6
    hi did you work it out in the end still got the same issue I want quest battery I have tried system info but not working yet thanks