mapbox-unity-sdk icon indicating copy to clipboard operation
mapbox-unity-sdk copied to clipboard

Initialising multiple Maps

Open HollyCamm opened this issue 4 years ago • 2 comments

I have a simplistic scene that initialises a map based on the users location and places some Markers at specified locations. This is within a GameObject that it not active on Awake. The scene starts with a Menu; when you press the map button, it sets active the Map scene GameObject.

If the Map scene isn't active on Awake, then the Map doesn't initialise when the GameObject is set active. However, if I place the LocationProvider in the root of the Hierarchy, it does initialise.

My issue comes when I want to use more than one Map. The LocationProvider specifies the AbstractMap and other components that relate to the first Map scene. This means that if I open the first Map scene, all is well, but if I open the second Map scene, the Map doesn't initialise.

I tried copying the LocationProvider from the second scene into the root Hierarchy - so I had 2, each referencing their own AbstractMap - this initialises the Map on both scenes, but in the Hierarchy, I notice it deletes one of the LocationProviders, and the Player Target doesn't stick to the Map on one of the scenes. I tried ticking Don't Destroy On Load for both of them but it still deletes one.

Does anyone know what I can do to initialise more than one Map successfully?

HollyCamm avatar Feb 26 '21 11:02 HollyCamm

Hey @HollyCamm! Have you tried unchecking InitializeOnStart under General Settings and then calling public virtual void Initialize(Vector2d latLon, int zoom) when you need that map? I think that was supposed to be the flow for this kind of setup.

brnkhy avatar Mar 05 '21 20:03 brnkhy

I'm having somewhat the same problem. When I load a new scene additively, the second map does not initialize. I can see it has to do with the fact that the LocationProviderFactory is being deleted because it's a static singleton. I think the implementation is strange because the LocationProviderFactory has a serialized reference to the abstract map. Therefore the same LocationProviderFactory cannot be used for multiple maps.

fabulastudios avatar Jan 13 '22 14:01 fabulastudios