Design your map in Mapbox and integrate it in Unity


This article explains you the procedure to design a map in Mapbox and then implement the Mapbox services in Unity3D.

What is Mapbox?

Mapbox is one of the best location data platform targeted for mobile and web applications.
You can use these services in Unity and create your own location and map based games.

Maps and location data optimized for Unity. Written from the ground up in C#, the Mapbox Unity SDK unlocks global data to generate custom 3D worlds, power location lookup, and incorporate traffic-based directions in your next Unity project.

The best part is that you can use the services for free until you cross the 50,000 monthly active mobile platform users mark.

First of all you have to sign up to get your account in Mapbox.
Now, Let’s design a map in Mapbox Studio and then use it in Unity.

Sign in and navigate to the Mapbox Studio to create a new basic Map Style.

You can see your map. We will change its look and feel by altering values in different Layers.

Scroll down in Layers section -> click on background -> change it’s color value to hsl(112, 80%, 71%)

Similarly change color values of below layers.
You will need colors for roads,buildings,land and water.

Change the Opacity field value of “building” layer to value 0.3

Fiddle around the color and opacity value of various layers in order to achieve your desired map look.

Your map should now look something like this.

Now let us add borders to our roads.
We will duplicate the “road_major” layer and rename it to “road_major border”.
“road_major” layer will stay on top of the “road_major border”.
Set the widths of both the layers in order to give it a border effect.

Do a similar procedure for “road_minor” layer.

Fiddle around the values to get your desired road border effect.
While increasing the width values make sure that the roads don’t overlap over each other.

For now, your road-border should look like this.

Now let us add a texture to the water layer.
Download the water.svg texture file and drag and drop this texture file into mapbox studio.
Duplicate the “water” layer. Add the water texture to the Pattern field with opacity of 0.1

You may replicate the same process for roads & buildings using road.svg and building.svg file.

Make additional adjustments to the map to get your desired look and then publish the map.

Congratulations! You successfully created a simple map style for your location-based game. You can now use this style with Mapbox Unity SDK, GL JS,iOS SDK, Android SDK .

We will now use this awesome map in Unity.

Integration of Mapbox with Unity

1.) Unity 5.6.0f3 or later.
2.) Download the Mapbox Unity SDK.

Create a new project in Unity and import the Mapbox Unity SDK package.
Create a new scene and save it.
Search for the “Attribution” prefab inside “Assets/Mapbox/Prefabs” and add it to our scene.

Before integrating the sdk we will get a new access token.
Navigate to Tokens and click “Create a new token” button.
Select scopes:list & styles:list and click “Generate” button.
Copy the new token and open Unity.
Select Mapbox > Configure to add your new access token.

Below are few scripts/assets from the SDK that we will be using to generate our Map in Unity.

  • Abstract Map
  • Abstract Tile Provider
  • Location Provider Factory
    • Device Location Provider
    • Editor Location Provider
    • Transform Location Provider
  • Map Visualizer
    • Flat Terrain Factory
    • Map Image Factory
    • Vector Tile Factory
  • Build Map At Location
  • Position With Location Provider
  • Player Tile Provider

Add this PlayerTileProvider.cs script to your project

Go through this video for further steps.

That’s it.
Finally you can see that your map is loaded inside Unity.
You can replace the cube with a 3D Character.

Build the project to a phone and you can see the map loaded in your phone.
Make sure the location services and internet connection is enabled.
Go for a walk and you will see the cube following your path in the Map.

You should now be capable of integrating Mapbox maps inside Unity and you can use it for your next location & map based game.

In the next tutorial, I will explain the procedure to add various custom dataset points in our map and then use the same points to the map loaded in Unity.

Meanwhile, If you have an idea for your next game and need any help in executing your concept, we will be more than happy to make it a reality. Contact Us


Sreejit Pillai Unity3D Game Developer

Games are one of my many passions and I always aim to create addictive and optimized games.

Comments are closed.