Lightship Map LayerPrefabPlacementBase hits a NullReferenceException when map scene is reloaded

Issue category: Lightship Maps
Maps Version : 0.4.0

  • Device type & OS version: iOS, iPhone 14 Pro
  • Host machine & OS version: Mac
  • Issue Environment : On Device

The map will work perfectly on the first load, but when I return after a scene reload the map tiles won’t load and the whole scene gets pixelated? Bizare behavior. (see video)

NullReferenceException: Object reference not set to an instance of an object.
  at Niantic.Lightship.Maps.MapLayers.Components.BaseTypes.LayerPrefabPlacementBase`1[T].PositionInstance (T instance, Niantic.Lightship.Maps.Core.Coordinates.LatLng& location, UnityEngine.Quaternion& rotation) [0x00000] in <00000000000000000000000000000000>:0 
  at Niantic.Lightship.Maps.MapLayers.Components.BaseTypes.LayerPrefabPlacementBase`1[T].OnMapOriginChanged () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Collections.Generic.List`1[T].ForEach (System.Action`1[T] action) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Collections.Generic.List`1[T].ForEach (System.Action`1[T] action) [0x00000] in <00000000000000000000000000000000>:0 
  at Niantic.Lightship.Maps.LightshipMapView.OnMapOriginChanged () [0x00000] in <00000000000000000000000000000000>:0 
  at Niantic.Lightship.Maps.Internal.MapUnitConverter.set_MapOrigin (Niantic.Lightship.Maps.Core.Coordinates.LatLng value) [0x00000] in <00000000000000000000000000000000>:0 
  at Niantic.Lightship.Maps.LightshipMapView.SetViewableAreaInternal (Niantic.Lightship.Maps.Core.Coordinates.LatLng& latLng, System.Double mapRadius) [0x00000] in <00000000000000000000000000000000>:0 
  at Niantic.Lightship.Maps.LightshipMapView.SetMapCenter (UnityEngine.Vector3 center) [0x00000] in <00000000000000000000000000000000>:0 
  at PlayerLocationController.Update () [0x00000] in <00000000000000000000000000000000>:0 ```

Hi David,

I’m sorry to hear you’re having trouble with Maps. Are you using the RefreshMap or ReloadMap methods in LightshipMapView? Could I see how you’re switching scenes and the code related to making the map reappear?

Kind regards,
Maverick L.

I have a bootstrapper scene that loads the map scene additively. I am not using ReloadMap or RefreshMap, simply letting the LightshipMap gameobject instantiate normally on scene load. I’ve narrowed the issue down to my custom map placement layers, when I disable both of them the map loads fine. This is also where the exception is getting thrown in the Lightship maps code (see NullReferenceException referenced above).

This exception is only happening on device (iOS), it works fine in the editor.

Here you can see how the scene is loaded, and the LightshipMap gameobject setup. I’m using 2 MapLayers for markers.

Thank you for your sharing that!

When you deploy to your iPhone, are you using a development build? From looking at the code, it looks like LayerPrefabPlacementBase Line 151 under PositionInstance where it calls GetTransform is causing the error; this means that somehow the instance of your outpost is resolving to null. Can you add a log message above the GetTransform call to see if instance is null as I suspect? In addition, in LightshipMapView in DetachAndHideChildObjects can you add a debug line above the while loop so we can see if that method is being called prior to the instance(s) becoming null? Please try this in the editor and on your iPhone with the development build flag enabled so you can see the printouts.

Thanks!

For these tests, I disabled the outpost map layer. I’m only using the VPS Marker map layer to simplify a bit.

DetachAndHideChildObjects is getting called before the MapLayer objects get instantiated.

Then the LayerPrefabPlacementBase instantiates/places the 5 VPS markers correctly. However, once OnMapOriginChanged starts getting called all the instances are null.

Full Xcode output (once the map loads for the 2nd time - when the NR exceptions start)

DetachAndHideChildObjects called
Niantic.Lightship.Maps.LightshipMapView:DetachAndHideChildObjects()
Niantic.Lightship.Maps.LightshipMapView:Awake()

 This method can cause UI unresponsiveness if invoked on the main thread. Instead, consider waiting for the `-locationManagerDidChangeAuthorization:` callback and checking `authorizationStatus` first.
New GPS Position: (Lat: 39.7579154968262, Lng: -104.984130859375)
VpsMarkerManager:HandleNewGpsPosition(LatLng)
<UpdateGpsLocation>d__17:MoveNext()
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

Requesting coverage from server...
VpsMarkerManager:RequestAreas()
VpsMarkerManager:HandleNewGpsPosition(LatLng)
<UpdateGpsLocation>d__17:MoveNext()
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

VPS Locations Found: 5
VpsMarkerManager:OnTryGetCoverage(AreaTargetsResult)
Niantic.Lightship.AR.VpsCoverage.<TryGetCoverage>d__10:MoveNext()
System.Threading.ExecutionContext:RunInternal(ExecutionContext, ContextCallback, Object, Boolean)
System.Runtime.CompilerServices.MoveNextRunner:Run()
System.Threading.Tasks.AwaitTaskContinuation:RunCallback(ContextCallback, Object, Task&)
System.Threading.Tasks.Task:FinishContinuations()
System.Threading.Tasks.Task`1:TrySetResult(TResult)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:SetResult(TResult)
Niantic.Lightship.AR.VpsCoverage.<RequestLocalizationTargetsAsync>d__7:MoveNext()
System.Threading.ExecutionContext:RunInternal(ExecutionContext, ContextCallback, Object, Boolean)
System.Runtime.CompilerServices.MoveNextRunner:Run()
System.Threading.Tasks.AwaitTaskContinuation:RunCallback(ContextCallback, Object, Task&)
System.Threading.Tasks.Task:FinishContinuations()
System.Threading.Tasks.Task`1:TrySetResult(TResult)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:SetResult(TResult)
Niantic.Lightship.AR.VpsCoverage.<SendPostAsync>d__0`2:MoveNext()
System.Threading.ExecutionContext:RunInternal(ExecutionContext, ContextCallback, Object, Boolean)
System.Runtime.CompilerServices.MoveNextRunner:Run()
UnityEngine.AsyncOperation:InvokeCompletionEvent()

PositionInstance: instance = Patterns (UnityEngine.GameObject)
Niantic.Lightship.Maps.MapLayers.Components.BaseTypes.LayerPrefabPlacementBase`1:PositionInstance(T, LatLng&, Quaternion&)
Niantic.Lightship.Maps.MapLayers.Components.BaseTypes.LayerPrefabPlacementBase`1:PlaceInstance(LatLng&, Quaternion&, String)
VpsMarkerManager:OnTryGetCoverage(AreaTargetsResult)
Niantic.Lightship.AR.VpsCoverage.<TryGetCoverage>d__10:MoveNext()
System.Threading.ExecutionContext:RunInternal(ExecutionContext, ContextCallback, Object, Boolean)
System.Runtime.CompilerServices.MoveNextRunner:Run()
System.Threading.Tasks.AwaitTaskContinuation:RunCallback(ContextCallback, Object, Task&)
System.Threading.Tasks.Task:FinishContinuations()
System.Threading.Tasks.Task`1:TrySetResult(TResult)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:SetResult(TResult)
Niantic.Lightship.AR.VpsCoverage.<RequestLocalizationTargetsAsync>d__7:MoveNext()
System.Threading.ExecutionContext:RunInternal(ExecutionContext, ContextCallback, Object, Boolean)
System.Runtime.CompilerServices.MoveNextRunner:Run()
System.Threading.Tasks.AwaitTaskContinuation:RunCallback(ContextCallback, Object, Task&)
System.Threading.Tasks.Task:FinishContinuations()
System.Threading.Tasks.Task`1:TrySetResult(TResult)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:SetResult(TResult)
Niantic.Lightship.AR.VpsCoverage.<SendPostAsync>d__0`2:MoveNext()
System.Threading.ExecutionContext:RunInternal(ExecutionContext, ContextCallback, Object, Boolean)
System.Runtime.CompilerServices.MoveNextRunner:Run()
UnityEngine.AsyncOperation:InvokeCompletionEvent()

PositionInstance: instance = Geisha Mural (UnityEngine.GameObject)
Niantic.Lightship.Maps.MapLayers.Components.BaseTypes.LayerPrefabPlacementBase`1:PositionInstance(T, LatLng&, Quaternion&)
Niantic.Lightship.Maps.MapLayers.Components.BaseTypes.LayerPrefabPlacementBase`1:PlaceInstance(LatLng&, Quaternion&, String)
VpsMarkerManager:OnTryGetCoverage(AreaTargetsResult)
Niantic.Lightship.AR.VpsCoverage.<TryGetCoverage>d__10:MoveNext()
System.Threading.ExecutionContext:RunInternal(ExecutionContext, ContextCallback, Object, Boolean)
System.Runtime.CompilerServices.MoveNextRunner:Run()
System.Threading.Tasks.AwaitTaskContinuation:RunCallback(ContextCallback, Object, Task&)
System.Threading.Tasks.Task:FinishContinuations()
System.Threading.Tasks.Task`1:TrySetResult(TResult)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:SetResult(TResult)
Niantic.Lightship.AR.VpsCoverage.<RequestLocalizationTargetsAsync>d__7:MoveNext()
System.Threading.ExecutionContext:RunInternal(ExecutionContext, ContextCallback, Object, Boolean)
System.Runtime.CompilerServices.MoveNextRunner:Run()
System.Threading.Tasks.AwaitTaskContinuation:RunCallback(ContextCallback, Object, Task&)
System.Threading.Tasks.Task:FinishContinuations()
System.Threading.Tasks.Task`1:TrySetResult(TResult)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:SetResult(TResult)
Niantic.Lightship.AR.VpsCoverage.<SendPostAsync>d__0`2:MoveNext()
System.Threading.ExecutionContext:RunInternal(ExecutionContext, ContextCallback, Object, Boolean)
System.Runtime.CompilerServices.MoveNextRunner:Run()
UnityEngine.AsyncOperation:InvokeCompletionEvent()

PositionInstance: instance = Trade Deficit 3 of 3 (UnityEngine.GameObject)
Niantic.Lightship.Maps.MapLayers.Components.BaseTypes.LayerPrefabPlacementBase`1:PositionInstance(T, LatLng&, Quaternion&)
Niantic.Lightship.Maps.MapLayers.Components.BaseTypes.LayerPrefabPlacementBase`1:PlaceInstance(LatLng&, Quaternion&, String)
VpsMarkerManager:OnTryGetCoverage(AreaTargetsResult)
Niantic.Lightship.AR.VpsCoverage.<TryGetCoverage>d__10:MoveNext()
System.Threading.ExecutionContext:RunInternal(ExecutionContext, ContextCallback, Object, Boolean)
System.Runtime.CompilerServices.MoveNextRunner:Run()
System.Threading.Tasks.AwaitTaskContinuation:RunCallback(ContextCallback, Object, Task&)
System.Threading.Tasks.Task:FinishContinuations()
System.Threading.Tasks.Task`1:TrySetResult(TResult)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:SetResult(TResult)
Niantic.Lightship.AR.VpsCoverage.<RequestLocalizationTargetsAsync>d__7:MoveNext()
System.Threading.ExecutionContext:RunInternal(ExecutionContext, ContextCallback, Object, Boolean)
System.Runtime.CompilerServices.MoveNextRunner:Run()
System.Threading.Tasks.AwaitTaskContinuation:RunCallback(ContextCallback, Object, Task&)
System.Threading.Tasks.Task:FinishContinuations()
System.Threading.Tasks.Task`1:TrySetResult(TResult)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:SetResult(TResult)
Niantic.Lightship.AR.VpsCoverage.<SendPostAsync>d__0`2:MoveNext()
System.Threading.ExecutionContext:RunInternal(ExecutionContext, ContextCallback, Object, Boolean)
System.Runtime.CompilerServices.MoveNextRunner:Run()
UnityEngine.AsyncOperation:InvokeCompletionEvent()

PositionInstance: instance = Eagle Riders' Name Wall Lion (UnityEngine.GameObject)
Niantic.Lightship.Maps.MapLayers.Components.BaseTypes.LayerPrefabPlacementBase`1:PositionInstance(T, LatLng&, Quaternion&)
Niantic.Lightship.Maps.MapLayers.Components.BaseTypes.LayerPrefabPlacementBase`1:PlaceInstance(LatLng&, Quaternion&, String)
VpsMarkerManager:OnTryGetCoverage(AreaTargetsResult)
Niantic.Lightship.AR.VpsCoverage.<TryGetCoverage>d__10:MoveNext()
System.Threading.ExecutionContext:RunInternal(ExecutionContext, ContextCallback, Object, Boolean)
System.Runtime.CompilerServices.MoveNextRunner:Run()
System.Threading.Tasks.AwaitTaskContinuation:RunCallback(ContextCallback, Object, Task&)
System.Threading.Tasks.Task:FinishContinuations()
System.Threading.Tasks.Task`1:TrySetResult(TResult)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:SetResult(TResult)
Niantic.Lightship.AR.VpsCoverage.<RequestLocalizationTargetsAsync>d__7:MoveNext()
System.Threading.ExecutionContext:RunInternal(ExecutionContext, ContextCallback, Object, Boolean)
System.Runtime.CompilerServices.MoveNextRunner:Run()
System.Threading.Tasks.AwaitTaskContinuation:RunCallback(ContextCallback, Object, Task&)
System.Threading.Tasks.Task:FinishContinuations()
System.Threading.Tasks.Task`1:TrySetResult(TResult)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:SetResult(TResult)
Niantic.Lightship.AR.VpsCoverage.<SendPostAsync>d__0`2:MoveNext()
System.Threading.ExecutionContext:RunInternal(ExecutionContext, ContextCallback, Object, Boolean)
System.Runtime.CompilerServices.MoveNextRunner:Run()
UnityEngine.AsyncOperation:InvokeCompletionEvent()

PositionInstance: instance = Crema Mural (UnityEngine.GameObject)
Niantic.Lightship.Maps.MapLayers.Components.BaseTypes.LayerPrefabPlacementBase`1:PositionInstance(T, LatLng&, Quaternion&)
Niantic.Lightship.Maps.MapLayers.Components.BaseTypes.LayerPrefabPlacementBase`1:PlaceInstance(LatLng&, Quaternion&, String)
VpsMarkerManager:OnTryGetCoverage(AreaTargetsResult)
Niantic.Lightship.AR.VpsCoverage.<TryGetCoverage>d__10:MoveNext()
System.Threading.ExecutionContext:RunInternal(ExecutionContext, ContextCallback, Object, Boolean)
System.Runtime.CompilerServices.MoveNextRunner:Run()
System.Threading.Tasks.AwaitTaskContinuation:RunCallback(ContextCallback, Object, Task&)
System.Threading.Tasks.Task:FinishContinuations()
System.Threading.Tasks.Task`1:TrySetResult(TResult)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:SetResult(TResult)
Niantic.Lightship.AR.VpsCoverage.<RequestLocalizationTargetsAsync>d__7:MoveNext()
System.Threading.ExecutionContext:RunInternal(ExecutionContext, ContextCallback, Object, Boolean)
System.Runtime.CompilerServices.MoveNextRunner:Run()
System.Threading.Tasks.AwaitTaskContinuation:RunCallback(ContextCallback, Object, Task&)
System.Threading.Tasks.Task:FinishContinuations()
System.Threading.Tasks.Task`1:TrySetResult(TResult)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:SetResult(TResult)
Niantic.Lightship.AR.VpsCoverage.<SendPostAsync>d__0`2:MoveNext()
System.Threading.ExecutionContext:RunInternal(ExecutionContext, ContextCallback, Object, Boolean)
System.Runtime.CompilerServices.MoveNextRunner:Run()
UnityEngine.AsyncOperation:InvokeCompletionEvent()

PositionInstance: instance = null
Niantic.Lightship.Maps.MapLayers.Components.BaseTypes.LayerPrefabPlacementBase`1:PositionInstance(T, LatLng&, Quaternion&)
Niantic.Lightship.Maps.MapLayers.Components.BaseTypes.LayerPrefabPlacementBase`1:OnMapOriginChanged()
System.Collections.Generic.List`1:ForEach(Action`1)
System.Collections.Generic.List`1:ForEach(Action`1)
Niantic.Lightship.Maps.LightshipMapView:OnMapOriginChanged()
Niantic.Lightship.Maps.Internal.MapUnitConverter:set_MapOrigin(LatLng)
Niantic.Lightship.Maps.LightshipMapView:SetViewableAreaInternal(LatLng&, Double)
Niantic.Lightship.Maps.LightshipMapView:SetMapCenter(Vector3)
PlayerLocationController:Update()

etc..

Xcode output cont. OnMapOriginChanged is trying to update all the positions, but somehow all the instances have become null.

PositionInstance: instance = null
Niantic.Lightship.Maps.MapLayers.Components.BaseTypes.LayerPrefabPlacementBase`1:PositionInstance(T, LatLng&, Quaternion&)
Niantic.Lightship.Maps.MapLayers.Components.BaseTypes.LayerPrefabPlacementBase`1:OnMapOriginChanged()
System.Collections.Generic.List`1:ForEach(Action`1)
System.Collections.Generic.List`1:ForEach(Action`1)
Niantic.Lightship.Maps.LightshipMapView:OnMapOriginChanged()
Niantic.Lightship.Maps.Internal.MapUnitConverter:set_MapOrigin(LatLng)
Niantic.Lightship.Maps.LightshipMapView:SetViewableAreaInternal(LatLng&, Double)
Niantic.Lightship.Maps.LightshipMapView:SetMapCenter(Vector3)
PlayerLocationController:Update()

NullReferenceException: Object reference not set to an instance of an object.
  at Niantic.Lightship.Maps.MapLayers.Components.BaseTypes.LayerPrefabPlacementBase`1[T].PositionInstance (T instance, Niantic.Lightship.Maps.Core.Coordinates.LatLng& location, UnityEngine.Quaternion& rotation) [0x00000] in <00000000000000000000000000000000>:0 
  at Niantic.Lightship.Maps.MapLayers.Components.BaseTypes.LayerPrefabPlacementBase`1[T].OnMapOriginChanged () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Collections.Generic.List`1[T].ForEach (System.Action`1[T] action) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Collections.Generic.List`1[T].ForEach (System.Action`1[T] action) [0x00000] in <00000000000000000000000000000000>:0 
  at Niantic.Lightship.Maps.LightshipMapView.OnMapOriginChanged () [0x00000] in <00000000000000000000000000000000>:0 
  at Niantic.Lightship.Maps.Internal.MapUnitConverter.set_MapOrigin (Niantic.Lightship.Maps.Core.Coordinates.LatLng value) [0x00000] in <00000000000000000000000000000000>:0 
  at Niantic.Lightship.Maps.LightshipMapView.SetViewableAreaInternal (Niantic.Lightship.Maps.Core.Coordinates.LatLng& latLng, System.Double mapRadius) [0x00000] in <00000000000000000000000000000000>:0 
  at Niantic.Lightship.Maps.LightshipMapView.SetMapCenter (UnityEngine.Vector3 center) [0x00000] in <00000000000000000000000000000000>:0 
  at PlayerLocationController.Update () [0x00000] in <00000000000000000000000000000000>:0 

PositionInstance: instance = null
Niantic.Lightship.Maps.MapLayers.Components.BaseTypes.LayerPrefabPlacementBase`1:PositionInstance(T, LatLng&, Quaternion&)
Niantic.Lightship.Maps.MapLayers.Components.BaseTypes.LayerPrefabPlacementBase`1:OnMapOriginChanged()
System.Collections.Generic.List`1:ForEach(Action`1)
System.Collections.Generic.List`1:ForEach(Action`1)
Niantic.Lightship.Maps.LightshipMapView:OnMapOriginChanged()
Niantic.Lightship.Maps.Internal.MapUnitConverter:set_MapOrigin(LatLng)
Niantic.Lightship.Maps.LightshipMapView:SetViewableAreaInternal(LatLng&, Double)
Niantic.Lightship.Maps.LightshipMapView:SetMapCenter(Vector3)
PlayerLocationController:Update()

NullReferenceException: Object reference not set to an instance of an object.
  at Niantic.Lightship.Maps.MapLayers.Components.BaseTypes.LayerPrefabPlacementBase`1[T].PositionInstance (T instance, Niantic.Lightship.Maps.Core.Coordinates.LatLng& location, UnityEngine.Quaternion& rotation) [0x00000] in <00000000000000000000000000000000>:0 
  at Niantic.Lightship.Maps.MapLayers.Components.BaseTypes.LayerPrefabPlacementBase`1[T].OnMapOriginChanged () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Collections.Generic.List`1[T].ForEach (System.Action`1[T] action) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Collections.Generic.List`1[T].ForEach (System.Action`1[T] action) [0x00000] in <00000000000000000000000000000000>:0 
  at Niantic.Lightship.Maps.LightshipMapView.OnMapOriginChanged () [0x00000] in <00000000000000000000000000000000>:0 
  at Niantic.Lightship.Maps.Internal.MapUnitConverter.set_MapOrigin (Niantic.Lightship.Maps.Core.Coordinates.LatLng value) [0x00000] in <00000000000000000000000000000000>:0 
  at Niantic.Lightship.Maps.LightshipMapView.SetViewableAreaInternal (Niantic.Lightship.Maps.Core.Coordinates.LatLng& latLng, System.Double mapRadius) [0x00000] in <00000000000000000000000000000000>:0 
  at Niantic.Lightship.Maps.LightshipMapView.SetMapCenter (UnityEngine.Vector3 center) [0x00000] in <00000000000000000000000000000000>:0 
  at PlayerLocationController.Update () [0x00000] in <00000000000000000000000000000000>:0 

PositionInstance: instance = null
Niantic.Lightship.Maps.MapLayers.Components.BaseTypes.LayerPrefabPlacementBase`1:PositionInstance(T, LatLng&, Quaternion&)
Niantic.Lightship.Maps.MapLayers.Components.BaseTypes.LayerPrefabPlacementBase`1:OnMapOriginChanged()
System.Collections.Generic.List`1:ForEach(Action`1)
System.Collections.Generic.List`1:ForEach(Action`1)
Niantic.Lightship.Maps.LightshipMapView:OnMapOriginChanged()
Niantic.Lightship.Maps.Internal.MapUnitConverter:set_MapOrigin(LatLng)
Niantic.Lightship.Maps.LightshipMapView:SetViewableAreaInternal(LatLng&, Double)
Niantic.Lightship.Maps.LightshipMapView:SetMapCenter(Vector3)
PlayerLocationController:Update()

NullReferenceException: Object reference not set to an instance of an object.
  at Niantic.Lightship.Maps.MapLayers.Components.BaseTypes.LayerPrefabPlacementBase`1[T].PositionInstance (T instance, Niantic.Lightship.Maps.Core.Coordinates.LatLng& location, UnityEngine.Quaternion& rotation) [0x00000] in <00000000000000000000000000000000>:0 
  at Niantic.Lightship.Maps.MapLayers.Components.BaseTypes.LayerPrefabPlacementBase`1[T].OnMapOriginChanged () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Collections.Generic.List`1[T].ForEach (System.Action`1[T] action) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Collections.Generic.List`1[T].ForEach (System.Action`1[T] action) [0x00000] in <00000000000000000000000000000000>:0 
  at Niantic.Lightship.Maps.LightshipMapView.OnMapOriginChanged () [0x00000] in <00000000000000000000000000000000>:0 
  at Niantic.Lightship.Maps.Internal.MapUnitConverter.set_MapOrigin (Niantic.Lightship.Maps.Core.Coordinates.LatLng value) [0x00000] in <00000000000000000000000000000000>:0 
  at Niantic.Lightship.Maps.LightshipMapView.SetViewableAreaInternal (Niantic.Lightship.Maps.Core.Coordinates.LatLng& latLng, System.Double mapRadius) [0x00000] in <00000000000000000000000000000000>:0 
  at Niantic.Lightship.Maps.LightshipMapView.SetMapCenter (UnityEngine.Vector3 center) [0x00000] in <00000000000000000000000000000000>:0 
  at PlayerLocationController.Update () [0x00000] in <00000000000000000000000000000000>:0 

PositionInstance: instance = null
Niantic.Lightship.Maps.MapLayers.Components.BaseTypes.LayerPrefabPlacementBase`1:PositionInstance(T, LatLng&, Quaternion&)
Niantic.Lightship.Maps.MapLayers.Components.BaseTypes.LayerPrefabPlacementBase`1:OnMapOriginChanged()
System.Collections.Generic.List`1:ForEach(Action`1)
System.Collections.Generic.List`1:ForEach(Action`1)
Niantic.Lightship.Maps.LightshipMapView:OnMapOriginChanged()
Niantic.Lightship.Maps.Internal.MapUnitConverter:set_MapOrigin(LatLng)
Niantic.Lightship.Maps.LightshipMapView:SetViewableAreaInternal(LatLng&, Double)
Niantic.Lightship.Maps.LightshipMapView:SetMapCenter(Vector3)
PlayerLocationController:Update()

NullReferenceException: Object reference not set to an instance of an object.
  at Niantic.Lightship.Maps.MapLayers.Components.BaseTypes.LayerPrefabPlacementBase`1[T].PositionInstance (T instance, Niantic.Lightship.Maps.Core.Coordinates.LatLng& location, UnityEngine.Quaternion& rotation) [0x00000] in <00000000000000000000000000000000>:0 
  at Niantic.Lightship.Maps.MapLayers.Components.BaseTypes.LayerPrefabPlacementBase`1[T].OnMapOriginChanged () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Collections.Generic.List`1[T].ForEach (System.Action`1[T] action) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Collections.Generic.List`1[T].ForEach (System.Action`1[T] action) [0x00000] in <00000000000000000000000000000000>:0 
  at Niantic.Lightship.Maps.LightshipMapView.OnMapOriginChanged () [0x00000] in <00000000000000000000000000000000>:0 
  at Niantic.Lightship.Maps.Internal.MapUnitConverter.set_MapOrigin (Niantic.Lightship.Maps.Core.Coordinates.LatLng value) [0x00000] in <00000000000000000000000000000000>:0 
  at Niantic.Lightship.Maps.LightshipMapView.SetViewableAreaInternal (Niantic.Lightship.Maps.Core.Coordinates.LatLng& latLng, System.Double mapRadius) [0x00000] in <00000000000000000000000000000000>:0 
  at Niantic.Lightship.Maps.LightshipMapView.SetMapCenter (UnityEngine.Vector3 center) [0x00000] in <00000000000000000000000000000000>:0 
  at PlayerLocationController.Update () [0x00000] in <00000000000000000000000000000000>:0 

PositionInstance: instance = null
Niantic.Lightship.Maps.MapLayers.Components.BaseTypes.LayerPrefabPlacementBase`1:PositionInstance(T, LatLng&, Quaternion&)
Niantic.Lightship.Maps.MapLayers.Components.BaseTypes.LayerPrefabPlacementBase`1:OnMapOriginChanged()
System.Collections.Generic.List`1:ForEach(Action`1)
System.Collections.Generic.List`1:ForEach(Action`1)
Niantic.Lightship.Maps.LightshipMapView:OnMapOriginChanged()
Niantic.Lightship.Maps.Internal.MapUnitConverter:set_MapOrigin(LatLng)
Niantic.Lightship.Maps.LightshipMapView:SetViewableAreaInternal(LatLng&, Double)
Niantic.Lightship.Maps.LightshipMapView:SetMapCenter(Vector3)
PlayerLocationController:Update()

NullReferenceException: Object reference not set to an instance of an object.
  at Niantic.Lightship.Maps.MapLayers.Components.BaseTypes.LayerPrefabPlacementBase`1[T].PositionInstance (T instance, Niantic.Lightship.Maps.Core.Coordinates.LatLng& location, UnityEngine.Quaternion& rotation) [0x00000] in <00000000000000000000000000000000>:0 
  at Niantic.Lightship.Maps.MapLayers.Components.BaseTypes.LayerPrefabPlacementBase`1[T].OnMapOriginChanged () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Collections.Generic.List`1[T].ForEach (System.Action`1[T] action) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Collections.Generic.List`1[T].ForEach (System.Action`1[T] action) [0x00000] in <00000000000000000000000000000000>:0 
  at Niantic.Lightship.Maps.LightshipMapView.OnMapOriginChanged () [0x00000] in <00000000000000000000000000000000>:0 
  at Niantic.Lightship.Maps.Internal.MapUnitConverter.set_MapOrigin (Niantic.Lightship.Maps.Core.Coordinates.LatLng value) [0x00000] in <00000000000000000000000000000000>:0 
  at Niantic.Lightship.Maps.LightshipMapView.SetViewableAreaInternal (Niantic.Lightship.Maps.Core.Coordinates.LatLng& latLng, System.Double mapRadius) [0x00000] in <00000000000000000000000000000000>:0 
  at Niantic.Lightship.Maps.LightshipMapView.SetMapCenter (UnityEngine.Vector3 center) [0x00000] in <00000000000000000000000000000000>:0 
  at PlayerLocationController.Update () [0x00000] in <00000000000000000000000000000000>:0 

PositionInstance: instance = null
Niantic.Lightship.Maps.MapLayers.Components.BaseTypes.LayerPrefabPlacementBase`1:PositionInstance(T, LatLng&, Quaternion&)
Niantic.Lightship.Maps.MapLayers.Components.BaseTypes.LayerPrefabPlacementBase`1:OnMapOriginChanged()
System.Collections.Generic.List`1:ForEach(Action`1)
System.Collections.Generic.List`1:ForEach(Action`1)
Niantic.Lightship.Maps.LightshipMapView:OnMapOriginChanged()
Niantic.Lightship.Maps.Internal.MapUnitConverter:set_MapOrigin(LatLng)
Niantic.Lightship.Maps.LightshipMapView:SetViewableAreaInternal(LatLng&, Double)
Niantic.Lightship.Maps.LightshipMapView:SetMapCenter(Vector3)
PlayerLocationController:Update()

NullReferenceException: Object reference not set to an instance of an object.
  at Niantic.Lightship.Maps.MapLayers.Components.BaseTypes.LayerPrefabPlacementBase`1[T].PositionInstance (T instance, Niantic.Lightship.Maps.Core.Coordinates.LatLng& location, UnityEngine.Quaternion& rotation) [0x00000] in <00000000000000000000000000000000>:0 
  at Niantic.Lightship.Maps.MapLayers.Components.BaseTypes.LayerPrefabPlacementBase`1[T].OnMapOriginChanged () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Collections.Generic.List`1[T].ForEach (System.Action`1[T] action) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Collections.Generic.List`1[T].ForEach (System.Action`1[T] action) [0x00000] in <00000000000000000000000000000000>:0 
  at Niantic.Lightship.Maps.LightshipMapView.OnMapOriginChanged () [0x00000] in <00000000000000000000000000000000>:0 
  at Niantic.Lightship.Maps.Internal.MapUnitConverter.set_MapOrigin (Niantic.Lightship.Maps.Core.Coordinates.LatLng value) [0x00000] in <00000000000000000000000000000000>:0 
  at Niantic.Lightship.Maps.LightshipMapView.SetViewableAreaInternal (Niantic.Lightship.Maps.Core.Coordinates.LatLng& latLng, System.Double mapRadius) [0x00000] in <00000000000000000000000000000000>:0 
  at Niantic.Lightship.Maps.LightshipMapView.SetMapCenter (UnityEngine.Vector3 center) [0x00000] in <00000000000000000000000000000000>:0 
  at PlayerLocationController.Update () [0x00000] in <00000000000000000000000000000000>:0 

Regardless of the issue, one suggestion would be to make the map more fault tolerant. If for some reason instance in PositionInstance() is null, it should not crash the entire map. I’m assuming it was designed such that instance would never be null though.

Here is my code where I spawn the markers using the LayerGameObjectPlacement if that helps.

using System.Collections.Generic;
using System.Linq;
using Niantic.Lightship.AR.VpsCoverage;
using Niantic.Lightship.Maps.MapLayers.Components;
using UnityEngine;

[RequireComponent(typeof(CoverageClientManager))]
public class VpsMarkerManager : Singleton<VpsMarkerManager>
{
    [SerializeField] LayerGameObjectPlacement _vpsMarkerSpawner;

    CoverageClientManager _coverageClientManager;

    List<VpsMarker> _markers = new();

    void OnEnable()
    {
        PlayerLocationController.OnNewGpsPosition += HandleNewGpsPosition;
    }

    void OnDisable()
    {
        PlayerLocationController.OnNewGpsPosition -= HandleNewGpsPosition;
    }

    protected override void OnAwake()
    {
        _coverageClientManager = GetComponent<CoverageClientManager>();
    }

    public void RequestAreas()
    {
        Debug.Log("Requesting coverage from server...");
        _coverageClientManager.TryGetCoverage(OnTryGetCoverage);
    }

    void HandleNewGpsPosition(Niantic.Lightship.Maps.Core.Coordinates.LatLng lng)
    {
        Debug.Log("New GPS Position: " + lng.ToString());

        _coverageClientManager.QueryLatitude = (float)lng.Latitude;
        _coverageClientManager.QueryLongitude = (float)lng.Longitude;

        RequestAreas();
    }

    void OnTryGetCoverage(AreaTargetsResult areaTargetsResult)
    {
        var responseText = string.Empty;

        if (areaTargetsResult.Status == ResponseStatus.Success)
        {
            areaTargetsResult.AreaTargets.Sort((a, b) =>
                a.Area.Centroid.Distance(areaTargetsResult.QueryLocation).CompareTo(
                    b.Area.Centroid.Distance(areaTargetsResult.QueryLocation)));

            Debug.Log("VPS Locations Found: " + areaTargetsResult.AreaTargets.Count);

            foreach (var areaTarget in areaTargetsResult.AreaTargets)
            {
                // Don't add duplicates
                // TODO: need a way to despawn them if out of range
                if (_markers.Any(m => m.VpsTarget.Identifier == areaTarget.Target.Identifier)) continue;

                var latLng = new Niantic.Lightship.Maps.Core.Coordinates.LatLng(
                                    areaTarget.Target.Center.Latitude, areaTarget.Target.Center.Longitude);

                var randNum = HexUtils.SideAngle(UnityEngine.Random.Range(0, 6));

                var pooledObj = _vpsMarkerSpawner.PlaceInstance(latLng, Quaternion.identity, areaTarget.Target.Name);
                var marker = pooledObj.Value.GetComponent<VpsMarker>();
                marker.Setup(areaTarget.Target);

                _markers.Add(marker);
            }
        }
        else
        {
            responseText = "Response : " + areaTargetsResult.Status;
        }

        // TODO put this back in once map NRE is fixed
        // OutpostMakerManager.Instance.SpawnOutposts();
    }

    public bool IsPositionNearAnyMaker(Vector3 position)
    {
        float declutterRange = 20f;
        return _markers.Any(m => Vector3.Distance(m.transform.position, position) <= declutterRange);
    }
}

Hi David,

We were out of office because of the Independence Day holiday. Maps is supposed to be fault-tolerant, so what you’re encountering is a bug and unintended behavior.

I have a couple workarounds you can try:

  1. Delete your placed instances on scene change and place them again when the scene returns to the map.
  2. Delete the entire map on scene change and recreate it when the game should show the map again.

API calls can be expensive and slow. You only need to do the VPS Coverage API calls once and then cache them if you’re going to use either of the workarounds. That way you don’t have to call the API every single time.

I will make a note of this bug and pass it along for our engineering team to look over.

Best,
Maverick L.