Iconic buildings

This example demonstrates how you can use the ReplaceFeatureCollectionModifier to place 3D models of iconic buildings. With this modifier, you can replace your corporate office locations with a branded building model, or spawn a highly detailed 3D object in place of a monument or building. The Mapbox Maps SDK for Unity contains some 3D models for your use. Click the button on the UI canvas to fly to the location of the selected iconic building.

Game object modifiers

The ReplaceFeatureCollectionModifier is a Game object modifier included in the SDK. Game object modifiers are ScriptableObjects that work with meshes and game objects to further allow you to decorate, enhance, or make modifications to your game objects. To create a new modifier, right click in your project window and navigate to Create > Mapbox > Modifiers

You can also create modifiers by clicking Add New in the Advanced > Modifier Options section of the AbstractMap script.

ReplaceFeatureCollectionModifier overview

To open the modifier for this example, navigate to MAP LAYERS > FEATURES, and then select ExtrudedBuildings under Map Features. Next, with ExtrudedBuildings selected, open then Behavior Modifiers section.

Under Game Object Modifiers, double click on the ReplaceFeatureCollectionModifier named ReplaceGlobalHeroStructuresModifier. This will open the modifier in your Inspector window and you will see the following settings:

  • Active: This boolean setting toggles the modifier on and off.

  • Features: This is an array that holds all features to add to the scene. You can increase the value of Size to add new elements to the array. You can also right click to duplicate or copy a selected element. For this example there are seven features inside of the array.

  • Prefab: This is the 3D object to spawn at the specified location. The title of the prefab will automatically be assigned as the title of the element.

  • Scale down with world: This setting scales the specified prefab to the size of the tile.

  • Prefab Locations: This is an array that holds all locations to all the buildings and features to be replaced with the supplied prefab. You can increase the value of Size to add new elements to the array. Click Search to find a feature, or paste in the latitude and longitude coordinates.

  • Explicitly Blocked Feature IDs: This is a list of ids on the ExtrudedBuildings layer to prevent from spawning. You can leave this empty unless you find an issue where the latitude and longitude coordinates are not properly filtering out the correct building to replaced.

Using this example as a guide you can place iconic buildings anywhere in the world, including your own neighborhood.