Change VPS LocationService at runtime

  • Issue category: VPS
  • Device type & OS version: iOS on iPhone 13 Pro
  • Host machine & OS version: M1 macOS Monterey
  • Issue Environment : On Device
  • Xcode version:
  • ARDK version: 2.1.0
  • Unity version: 2021.3.7

I am trying to use VPS in a mix of environments, indoors and outdoors. For outdoors I use a regular location service and for indoors I use a SpoofLocationService with specific GPS coordinates. It all works fine separately, but I cannot switch between them at runtime. I am completely stopping, deleting and recreating all the VPS-related objects when switching between the locations services but I always get an error message when creating a new WayspotAnchorService with the new LocationService:

This ARSession is already listening to a LocationService instance

This is how I am stopping VPS:

if(locationService != null) {
    locationService = null;
if(wayspotAnchorService != null) {
    wayspotAnchorService = null;

And restarting:

if(indoors) {
    locationService = LocationServiceFactory.Create(RuntimeEnvironment.Mock);
    (locationService as SpoofLocationService).SetLocation(spoofLatLon);
    locationService = LocationServiceFactory.Create(session.RuntimeEnvironment);

locationService.LocationUpdated += OnLocationUpdated;

wayspotAnchorService = new WayspotAnchorService(session, locationService, wayspotConfig);

I looked through the ARDK source code but there doesn’t seem to be a way to change the location service for the ARSession?

Hello Julian,

Unfortunately, it is not possible to switch out the location service once the session is in runtime.

Try to enable Continuous Location to force the VPS system to keep attempting localizing.

Keep in mind VPS Localization Best Practices recommending users only localize with one wayspot per session, and note the VPS session will restart when searching for a second wayspot.

Find more information about Localizing with VPS in our documentation.

Hi Moranda,

Unfortunately, it is not possible to switch out the location service once the session is in runtime.

You mean VPS session or ARSession?

I do restart the VPS completely between VPS wayspots. As I mentioned above, I stop VPS, delete all the related objects and re-create them again. But I don’t re-create the ARSession… would I need to in order to switch location services?


I’m referring to the VPS Session. VPS can be configured to do continuous localization by setting WayspotAnchorsConfiguration.ContinuousLocalizationEnabled to True when you start VPS. When continuous localization is enabled, VPS will continue to localize to your current surroundings after the initial localization. You can try to recreate the ARSession for testing purposes, but keep in mind best practices I mentioned in the previous response. Let me know your results.

I am restarting the VPS session between localizations.

But what I am wondering about is how to change the locationServices while I am restarting VPS… The ARSession complains that it’s already listening to a LocationService instance and I found no way of setting a different one.

Currently, there’s no way to reassign a new location service to an existing ARSession. You’ll need to Dispose () your existing session, then create a new one. Engineering has been made aware of the request. Keep up with our future plans for features and functionality as we build the Lightship platform.