When running a simple WPS scene and trying to place multiple objects at different positions using the AR World Positioning Manager and it’s OriginLatitude / Longitude method, the latitude and longitude values will not be updated after the initial start of the app.
Example: I used the script below to spawn cubes with a random material. However when trying to place multiple cubes at different locations, only the very first lat and long values will be used. When I restart the app at a different location, it’s now that different location.
using System;
using System.Collections;
using System.Collections.Generic;
using Niantic.Experimental.Lightship.AR.WorldPositioning;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.UI;
using Random = UnityEngine.Random;
public class PlaceNewObjectInfront : MonoBehaviour
{
[SerializeField] private GameObject _objectToSpawn;
[SerializeField] private ARWorldPositioningObjectHelper _positioningObjectHelper;
[SerializeField] private Camera mainCam;
[SerializeField] private Button placeObject;
[SerializeField] private ARWorldPositioningManager _positioningManager;
[SerializeField] private List<Material> _materials;
private List<GameObject> instantiatedObjects;
void Start()
{
instantiatedObjects = new();
placeObject.onClick.AddListener(PlaceDownObject);
StartCoroutine(PrintPosition());
}
IEnumerator PrintPosition()
{
while (true)
{
Debug.Log("Position is => long :" + _positioningManager.WorldTransform.OriginLongitude +
" lat: " + _positioningManager.WorldTransform.OriginLatitude +
" Alt : " + _positioningManager.WorldTransform.OriginAltitude);
yield return new WaitForSeconds(.7f);
}
}
void PlaceDownObject()
{
// Vector3 position = mainCam.transform.position;
GameObject newObject = Instantiate(_objectToSpawn);
newObject.GetComponent<MeshRenderer>().material = _materials[Random.Range(0, _materials.Count-1)];
newObject.name = $"{newObject.name} {instantiatedObjects.Count}";
instantiatedObjects.Add(newObject);
var lat = _positioningManager.WorldTransform.OriginLatitude;
var longitude = _positioningManager.WorldTransform.OriginLongitude;
var altitude = 0;
_positioningObjectHelper.AddOrUpdateObject(newObject, lat, longitude , altitude , Quaternion.identity );
Debug.Log("(NO DEBUG) Adding Object " + newObject + " at Latitude:" + lat + " Longitude: " + longitude + " Altitude: " + altitude);
}
}