> For clean Markdown of any page, append .md to the page URL. > For a complete documentation index, see https://docs.stereolabs.com/docs/integrations/unreal-engine-5/spatial-mapping/llms.txt. > For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.stereolabs.com/_mcp/server. # Environmental Mapping with UE5 In this tutorial, you will learn how to build a procedural mesh of your room and add physical interactions between virtual objects and the real world using [Spatial Mapping](/docs/development/zed-sdk/modules/spatial-mapping/). ## Introduction Spatial mapping captures a mesh of your environment, letting virtual elements interact with it in much the same way they would with the floors, walls, and other objects in a video game. It allows you to use Unreal's built-in physics engine, adding convincing physical behavior to virtual objects. This way, they can collide with the real world, bounce off of it in appropriate directions, accelerate correctly and be affected by gravity and other forces in the real world. ## Prepare your project Either: * Open the level **L\_SpatialMapping** in `Content/ZED/Levels` and explore its setup along this page * Or follow the steps in [Creating a project](/docs/integrations/unreal-engine-5/configuring-your-project/) if you don't know how to create and set up a new project, then follow the next steps. ## Mapping an Area To use spatial mapping you will need two actors: the **BP\_SpatialMapping\_Manager** to scan and retrieve the mesh and a procedural mesh to create and display the mesh in the virtual world. The plugin provides an example blueprint, **BP\_SpatialMapping\_Mesh**, to let you see how to use the procedural mesh. * Go to *ZED/Blueprints/SpatialMapping* and add **BP\_SpatialMapping\_Manager** and **BP\_SpatialMapping\_Mesh** to the scene. * Now we need to initialize the scanning mesh actor. Open the level blueprint and initialize the mesh. ![image](/_fern-img/645bd373dff2d28ae03d567396d137a07e904b918c6ff89f782af33fe13aff5d.webp) * Click on the **BP\_SpatialMapping\_Manager** actor in the world outliner to see the settings. We recommend using the following set of parameters for mapping: * Resolution = `Medium` (Small variations in the geometry will disappear, useful for big objects) * Range = `Medium` (Medium depth range. `Long` will take into account objects that are far, useful for outdoor purposes.) * Filtering = `Low` (Clean the mesh by closing small holes and removing isolated faces.) For more details on Spatial Mapping parameters, see this [section](/docs/development/zed-sdk/modules/spatial-mapping/#spatial-mapping-parameters). ![image](/_fern-img/eb07b05b2b9d7218ab6b4089ebe2a0e408f50ee7d1d4bd87379466718ae36626.webp) Now, let's start mapping the area. * Play the level. * Click on the **BP\_SpatialMapping\_Manager** in the world outliner. You should see the spatial mapping controls. ![image](/_fern-img/98367a88b5103064dcaddc1353b169b70a2d8eb6c2a6f94344b5ef45cb6c01d4.webp) * Click on **Start** to initialize the spatial mapping and start mapping the area. * Move your camera around. The mesh should become visible. * Once you've mapped enough of the room, click on **Stop**. * Click **Filter** to filter (clean up) the mesh. This process may take some time depending on your settings. * If you want to save your mesh, click **Save**. * When finished, click on **Disable** to disable spatial mapping. ## Using Physics During mapping, use the blueprint **BP\_SpatialMapping\_Mesh** to automatically generate a mesh of the area and enable collisions between virtual objects and the real scene.