Skip to main content

Unity SDK

Add AR Clip VPS to a Unity project. The SDK finds the user's position on your VPS maps and places content in the right spot, on ARKit (iOS) and ARCore (Android) devices.

Before you start​

  • Unity 2022.3 LTS or newer
  • A test device with ARKit or ARCore support
  • Git LFS, if you clone the sample project (it has large assets)

Install​

Choose one of two ways.

Clone the sample project​

git clone https://github.com/WebAR-Studio/was-vps-unity.git

Open the project in Unity 2022.3 or newer. The scenes in Assets/Scenes show working setups.

Add with the Package Manager​

  1. Open Window → Package Manager.
  2. Click + → Add package from Git URL….
  3. Paste https://github.com/WebAR-Studio/was-vps-unity.git?path=/Assets.

Unity downloads the SDK into Packages/was-vps-unity.

Set up the scene​

  1. Create or open a scene that is ready for AR Foundation. It needs an AR Session and an AR Session Origin.
  2. Add VPSLocalisationService to an empty GameObject. This component runs localization.
  3. In the Inspector, assign:
    • AR Session
    • AR Session Origin
    • the AR camera and UI hooks, if you need them (see the sample scenes)
  4. Enter your VPS API Key and at least one Location ID.
  5. Optional: while you debug, turn on Save Images Locally or Save Logs In File.
Need an API key?

Start localization​

Control localization from your own script. Add the component below and assign the VPSLocalisationService reference in the Inspector.

using UnityEngine;
using WASVPS;

public class VPSBootstrap : MonoBehaviour
{
[SerializeField] private VPSLocalisationService vpsService;

private void Start()
{
vpsService.OnPositionUpdated += HandlePositionUpdated;
vpsService.OnErrorHappend += HandleError;

var settings = new SettingsWASVPS(
new[] { "your-location-id" },
failsCountToReset: 5
);

settings.ApiKey = "your-api-key";
settings.LocalizationTimeout = 2.0f;

vpsService.StartVPS(settings);
}

private void HandlePositionUpdated(LocationState state)
{
Debug.Log($"Localized at {state.Localisation.VpsPosition}");
}

private void HandleError(ErrorInfo error)
{
Debug.LogError(error.LogDescription());
}
}

Inspector settings​

PropertyWhat it doesDefault
Start On AwakeStarts localization when the scene loadsfalse
Force Mock In EditorAlways uses the mock provider when you run in the Editortrue
Send GPSAdds the device's GPS data to each VPS requestfalse
Fails Count To ResetHow many failures in a row reset the session5
Save Images LocallySaves captured frames for debuggingfalse

Test and debug​

  • Turn on Force Mock In Editor and use the included mock textures to test without a device.
  • Call VPSLogger.SetLogLevel(LogLevel.VERBOSE) to see HTTP requests, responses and errors in the console.
  • If localization never succeeds, check that your API key is valid and that each location ID matches a VPS map you have.

Examples​

  • See Assets/Scenes/TestScene.unity and Assets/Scripts/ExampleVPS.cs in the sample project for working examples.
  • Use VPS poses in your own logic: spawn anchors, align 3D content or update the UI.

Next: Unity platforms — build for phones, headsets and glasses.