Location doesn't appear to be tracked after calling ARLocationManager.StartTracking() programmatically

Include the following details (edit as applicable):

  • Issue category: ARDK Documentation / VPS / Scanning Framework
  • Device type & OS version: Android
  • Host machine & OS version: Windows 11 Version 10.0.26200 Build 26200
  • Issue Environment : On Device
  • Xcode version:
  • ARDK version: 3.15.0-2508040839
  • Unity version: 6000.0.53f1

Description of the issue:

When I am physically at the VPS location I am attempting to track, I do not get a hit on the location

I have loaded 2 VPS locations in the AR Location manager on the XR Origin (with AR Location set to none), and have successfully ran the Persistent AR Demo sample code in the past. My goal is to track these locations from code (and one day add the locations to the location manager in code as well), but I am having trouble with this.

Here is the code:

// Wait for ARSession to be tracking
yield return new WaitUntil(() => ARSessionGuard.IsSessionTracking);

//Add event listener for when the tracking state of the location being tracked 
//changes
_arLocationManager.locationTrackingStateChanged += OnLocationTrackingStateChanged;


var arLocations = _arLocationManager.ARLocations;

Debug.Log($"[{DateTime.Now}] StartTracking: {arLocations[index].Payload.ToBase64()}");

_arLocationTrackingText.text = $"StartTracking: {arLocations[index].name}";

_arLocationManager.SetARLocations(arLocations[index]);
_arLocationManager.StartTracking();

After _arLocationManager.StartTracking(); is called, I do not get any event handler calls telling me that tracking has started. My handler code is simple:

private void OnLocationTrackingStateChanged(ARLocationTrackedEventArgs args)
{
            Debug.Log(
                $"Location Tracking State: {args.ARLocation}, {args.Tracking}, {args.TrackingConfidence}, {args.TrackingStateReason}");

}

Here’s what I have confirmed:

  • I called SetARLocations(...) before StartTracking()as shown in the code above
  • I subscribed to the event handler before calling StartTracking()
  • I confirmed ARSession is running before calling SetARLocations(...) and StartTracking()
  • I confirmed location permissions are granted on the target
  • I confirmed the correct event handler method name
  • I confirmed that I am using a valid ARLocation to track. The same location works when it is selected in the Inspector before compiling, and in code I am just selecting the same location from the ARLocation array.
  • I dump the debug out for the entire app to a text box on screen and do not see any error messages that would indicate a problem anywhere.

Hi Michael,

I’m happy to assist. With the yield returns in your code, make sure you call that function with StartCoroutine. A regular function call won’t work there. Can you share where the function is called?

Kind regards,
Maverick L.

Sure, it’s called here:

namespace AR
{
    public class PersistentAR : MonoBehaviour
    {
private void Start()
{
    //Start tracking location
    StartCoroutine(LoadNextLocation());
}


 }
}

Hi Michael,

Due to technical difficulties, my response to you never went through. I sincerely apologize for the delay.

Looks like this could be a race condition where the event handler is being registered too late for it to handle the event. I would recommend registering the event handler, i.e. placing the _arLocationManager.locationTrackingStateChanged += OnLocationTrackingStateChanged before your function yields.

Please give that a try and let me know how it goes!

Kind regards,
Maverick L.

Hi Maverick,

Thanks for the response. I’m circling back to this one and will keep you posted. Also: is there any sample code available for updating the VPS location being track through script or similar?