Mapbox Unity SDK
Current Version: v1.1.0 View changelog
Vector map of the world
Global digital elevation model
Cloudless satellite base map
Custom data
Overview

The Mapbox Unity SDK is a collection of tools for building Unity applications from real map data. It enables Unity developers to interact with Mapbox web services APIs (including the Maps, Geocoding and Directions APIs) and create game objects via a C#-based API and graphical user interface.

Install the Mapbox Unity SDK 1. Download the package
Get an access token and download the SDK directly." Sign up for an account, then follow the step-by-step walkthrough to help you get started with the Unity SDK.
2. Get an access token

If you don't have a Mapbox account, sign up for one here, then navigate to the token page in Mapbox Studio and copy your default public token to your clipboard. When you installed the Mapbox Unity SDK a Mapbox menu was added to Unity. Click Mapbox > Configure Access from the Unity Editor menu, then paste your token into the Token field. If your token is valid, it will be saved to a text file named StreamingAssets/MapboxAccess.text. At runtime, the contents of this file will be read and cached for FileSource request purposes.

3. Add a map
Many games and applications built with the Mapbox Unity SDK start by building a basemap from map tiles. To add a basemap:
  1. Create a new C# script named RasterMap.
  2. Add the code below to your RasterMap script.
    using UnityEngine;
    using Mapbox.Map;
    using Mapbox.Unity;
    using Mapbox.Utils;
    public class RasterMap : MonoBehaviour, Mapbox.Utils.IObserver<RasterTile>
    {
    void Start()
    {
    var map = new Map<RasterTile>(MapboxAccess.Instance);
    map.Zoom = 2;
    map.Vector2dBounds = Vector2dBounds.World();
    map.MapId = "mapbox://styles/mapbox/streets-v10";
    map.Subscribe(this);
    map.Update();
    }
    public void OnNext(RasterTile tile)
    {
    if (tile.CurrentState == Tile.State.Loaded)
    {
    if (tile.HasError)
    {
    Debug.Log("RasterMap: " + tile.ExceptionsAsString);
    return;
    }
    var tileQuad = GameObject.CreatePrimitive(PrimitiveType.Quad);
    tileQuad.transform.SetParent(transform);
    tileQuad.name = tile.Id.ToString();
    tileQuad.transform.position = new Vector3(tile.Id.X, -tile.Id.Y, 0);
    var texture = new Texture2D(0, 0);
    texture.LoadImage(tile.Data);
    var material = new Material(Shader.Find("Unlit/Texture"));
    material.mainTexture = texture;
    tileQuad.GetComponent<MeshRenderer>().sharedMaterial = material;
    }
    }
    }
  3. Create an empty game object and add the RasterMap component to it.
  4. Press Play and watch the map build as tiles are loaded.
4. Add other features

A number of examples are bundled with the Mapbox Unity SDK to help you learn how to add geocoding, directions, traffic and more advanced features to your game or application. For each example, associated scripts and resources can be found in the same root directory as the scene itself.

Want to dive deeper? Read our step-by-step tutorials about mesh generation. Tutorials on contour lines, 3D POIs, and more coming soon.

Attribution
Attribution guidelines Help
Learn more about what kinds of attribution Mapbox require and why.
You must include the the Mapbox wordmark and attribution notice on any map that uses the Mapbox Unity SDK. We provide an Attribution prefab that includes all required information and can be customized via uGUI.

You may adjust the position of the Mapbox wordmark and attribution notice, but they must remain visible on the map. You may also change the background and text color of the attribution notice to best match your design aesthetics, but all information must be clearly legible.

You may not otherwise alter the Mapbox wordmark or text attribution notice. If you wish to otherwise relocate or to remove the Mapbox wordmark, please contact our sales team to discuss options available under our Enterprise plans.