Search Unity

Question Call (directly or indirectly) a Unity XR function from Android

Discussion in 'XR Interaction Toolkit and Input' started by rogermiranda1000, Mar 10, 2023.

  1. rogermiranda1000

    rogermiranda1000

    Joined:
    Nov 5, 2016
    Posts:
    5
    Hi, first of all I'd like to explain my problem and the tools/limitations I have:
    I'd like to stream the face-tracking data in my VR glasses (PICO 4 enterprise) while using other apps, and the only tool PICO provide is the Unity SDK to access that tracking data.
    PICO uses Android, and it won't allow multiple apps being opened at the same time (when you open an app, the previous one closes), that means that I have to get&send the face-tracking data using Android services. I've tried to copy the PICO code that they provide on a native Android Studio aplication, but for security reasons they only allow access to the face cameras to system aplications (so I have to use the Unity SDK).

    The information can be read by calling the Unity PX functions like `PXR_EyeTracking.GetCombineEyeGazeVector(out v)`, and as I've said you can keep a service running sending UDP packets to the computer. You can check a Unity project example of what I've said here.
    Now, the problems: I don't know how to call Unity XR from within Android, so what I've done is to invoke a C# function using `UnityPlayer.UnitySendMessage("XR Rig", "myAction", "")`. That works fine in-game, but once you close the app you can't invoke the `UnityPlayer` anymore. I've tried to export the Unity project into Android and try to re-launch the app creating a new Android intent, but that causes the previous opened aplication to lose focus, causing it to be closed.

    So, I think one of the following solutions would work, and I'd be pleased if you can help me with it:
    • Find a way to launch `PXR_EyeTracking` using Unity libraries, but inside native Android
    • Find a way to invoke a Unity C# function, even after destroying the `UnityPlayer`