Get localization confidence updates

  • ARDK version: 3.0 beta 4
  • Unity version: 2021,3,27f1

Description of the issue:

Hey Lightship!

So i’m building a VPS project and i’d like to give players a rough idea of how close they are to localizing properly. In the debugs i was able to find the localization confidences and i’m trying to pass those to a UI element that fills up when players get closer to localizing.

Here’s my attempt, it’s not firing atm:

using Niantic.Lightship.AR.Subsystems;
using UnityEngine;
using UnityEngine.SubsystemsImplementation.Extensions;
using UnityEngine.UI;

[RequireComponent(typeof(Image))]
public class VPSConfidenceProgressBarView : MonoBehaviour
{
    private ARLocationManager _locationManager;
    private XRPersistentAnchorSubsystem.Provider _provider;

    private Image _image;
    
    void Start()
    {
        _image = GetComponent<Image>();
        _locationManager = FindObjectOfType<ARLocationManager>();
        if (_locationManager == null)
            return;
        
        _provider = _locationManager.subsystem.GetProvider();
    }

    private void Update()
    {
        if (_provider == null)
        {
            _locationManager = FindObjectOfType<ARLocationManager>();
            if (_locationManager == null)
                return;
        
            _provider = _locationManager.subsystem.GetProvider();

            if (_provider == null)
                return;
        }
        
        var gotLocalizationStatus = _provider.GetLocalizationStatusUpdate(out var localizationStatuses);
        if (gotLocalizationStatus)
        {
            Debug.Log("got a change!");
            foreach (var status in localizationStatuses)
            {
                _image.fillAmount = status.LocalizationConfidence;
            }
        }
    }
}

If anyone can see what i’m doing wrong here i’d love to hear it :slight_smile:

Hi Merijn,

The returns make it a bit difficult to debug. Could you add some Debug.Log statements to see if the location manager and provider are being set? Also, I’d recommend scheduling a coroutine to find those components rather than checking every Update call.

Kind Regards,
Maverick L.

Hello Merjin!

Thanks for taking a look at Lightship! To start off, I highly recommend updating to the most recent 3.o public release version to check if that resolves the issues you’re encountering. Should the problems remain, please don’t hesitate to post on these forums!

As for VPS Localization confidence, we’ve found this “LocalizationConfidence” to be dubious. We’ve put this API in place as we investigate, but it’s my advice as of Nov 3rd 2023 to avoid relying on this data within your application. It’s important to note that the metric isn’t linear and won’t necessarily reach 100% even when a localization is successful.

A more informative approach to guide your users is to use the “Status” field within the localizationStatuses. This status field has 4 potential values:

public enum LocalizationStatus : byte
{
    Unknown = 0,
    Failure,
    Limited,
    Success,
}

“Unknown” here is an internal error for us, you shouldn’t see this. If you do, please let us know! Failure and success are self explanatory, but the “Limited” status is how I think we can help guide users.

“Limited” means we can recognize that the user is at the location we’re attempting to track, but we didn’t get enough information to estimate a full positional and rotational offset from the location’s default anchor. If a user receives a “Limited” status, most of the time they should be able to eventually get a successful localization at their current location. I don’t think these statuses map very clearly to a loading bar, but could be surfaced to users to help catch when they’re not even close to the right location.

Thanks again and welcome to the Lightship community!