Using Native ARKit Object Tracking in Unity

Hello,

Has anyone had success with implementing object tracking in Unity or adding native tracking capability to the VisionOS project built from Unity?

I am working on an application for Vision Pro mainly in Unity using Polyspatial. The application requires me to track objects and make decisions based on tracked object's location. I was able to create an object tracking application on Native Swift, but could not successfully combine this with my Unity project yet. Each separate project (Main Unity app using Polyspatial and the native app on Swift) can successfully build and be deployed onto VisionPro.

I know that Polyspatial and ARFoundation does not have support for ARKit's object tracking feature for VIsion Pro as of today, and they only support image tracking inside Unity. For that reason I have been exploring different ways of creating a bridge for two way interaction of the native tracking functionality and the other functionality in Unity.

Below are the methods I tried and failed so far:

  1. Package the tracking functionality as a Swift Plugin and access this in Unity, and then build for Vision Pro: I can create packages and access them for simple exposed variables and methods, but not for outputs and methods from ARKit, which throw dependency errors while trying to make the swift package.

  2. Build project from Unity to VIsion Pro and expose a boolean to start/stop tracking that can be read by the native code, and then carry the tracking classes into the built project. In this approach I keep getting an error that says _TrackingStateChanged cannot be found, which is the class that exposes the bool toggled by the Unity button press:

using System.Runtime.InteropServices;

public class UnityBridge { [DllImport("__Internal")] private static extern void TrackingStateChanged(bool isTracking);

public static void NotifyTrackingState()
{
    // Call the Swift method
    TrackingStateChanged(TrackingStartManager.IsTrackingActive());
}

}

This seems to be translated to C++ code in the ill2cpp output from Unity, and even though I made sure that all necessary packages were added to the target, I keep receiving this error. from the UnityFramework plugin:

Undefined symbol: _TrackingStateChanged

  1. I have considered extending the current Image Tracking approach in ARFoundation to include object tracking, but that seems to be too complicated for my use case and time frame for now.

  2. The final resort will be to forego Unity implementation and do everything in native code. However, I really want to be able to use Unity's conveniences and I have very limited experience with Swift development.

Using Native ARKit Object Tracking in Unity
 
 
Q