Accessing the Map Object in Your Own Scripts
October 23, 2025 · View on GitHub
If you want to use the map object in your own code (for example, to query tiles, add layers, or respond to map events), the recommended approach is to:
- Reference the
MapBehaviourCorecomponent in your script. - Subscribe to its
Initializedevent. - Store the resulting
MapboxMapinstance when it becomes available.
Here’s a simple example:
using UnityEngine;
using Mapbox.Unity.Map;
public class Test : MonoBehaviour
{
public MapBehaviourCore MapCore;
private MapboxMap _map;
public void Awake()
{
MapCore.Initialized += (map) =>
{
_map = map;
Debug.Log("Map is initialized");
};
}
}
What This Does
- The script listens for the map’s initialization event.
- When the map is ready, it assigns it to the private
_mapfield. - You can then safely use
_mapfor all your map-related logic.