# Rebuilding dynamic navmesh via c++ stops working after switching levels 

**URL:** <https://forums.unrealengine.com/t/rebuilding-dynamic-navmesh-via-c-stops-working-after-switching-levels/2459652>\
**Category:** AI\
**Tags:** dynamic-navmesh, unreal-engine, CPP, question\
**Created:** [April 16, 2025, 1:51pm UTC](https://forums.unrealengine.com/t/rebuilding-dynamic-navmesh-via-c-stops-working-after-switching-levels/2459652 "2025-04-16T13:51:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kitun](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@kitun](https://forums.unrealengine.com/u/kitun)\
**Post date:** [April 16, 2025, 1:51pm UTC](https://forums.unrealengine.com/t/rebuilding-dynamic-navmesh-via-c-stops-working-after-switching-levels/2459652/1 "2025-04-16T13:51:01Z")

</div>

I use simple c++ to rebuild navmesh at runtime when the level changes. This works no problem. However after I load any other level containing a navmesh and return to this one, the code stops working. There are no error logs, it simply generates an empty navmesh and displays a log that building took 0.0 seconds.

```auto
UNavigationSystemV1* NavSystem = UNavigationSystemV1::GetCurrent(GetWorld());
if (NavSystem->IsInitialized())
{
	NavMeshBounds->SetActorLocation(SomeOtherLocation); // move bounds to new location
	NavigationSystemV1->Build(); //build the nav mesh
        //this works when this is the first level loaded, after i load a different one and return it breaks
}

```

Any help would be greatly appreciated!

EDIT: I’m using Unreal 5.2

---

<div class="post-metadata">

**Author:** ![BRGDemianLopez](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/brgdemianlopez/32/1052421_2.png) [@BRGDemianLopez](https://forums.unrealengine.com/u/BRGDemianLopez)\
**Post date:** [April 16, 2025, 2:16pm UTC](https://forums.unrealengine.com/t/rebuilding-dynamic-navmesh-via-c-stops-working-after-switching-levels/2459652/2 "2025-04-16T14:16:18Z")

</div>

Hey @kitun, could you share a few more details?

The code you’re showing—where is it exactly? Is it in the `BeginPlay` of an actor or somewhere else?  
What configuration do you have for the NavMesh? I assume it’s dynamic (based on the title), but just to confirm.

Does the other level already contain a `RecastNavMesh` actor?

Also, why are you rebuilding it manually if the dynamic NavMesh should automatically rebuild when the geometry or level changes?

---

<div class="post-metadata">

**Author:** ![kitun](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@kitun](https://forums.unrealengine.com/u/kitun)\
**Post date:** [April 16, 2025, 2:31pm UTC](https://forums.unrealengine.com/t/rebuilding-dynamic-navmesh-via-c-stops-working-after-switching-levels/2459652/3 "2025-04-16T14:31:01Z")

</div>

Hi, thanks for reaching out!

I use the code whenever I add a tile to the level (50x50 meters approx) Its a very simple function that makes sure the level never ends pic below:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/e/2/fe26d87f575c2bcb25facfa2e947c6a540fc2734.png)  
Example:

1. Player reaches tile 2
2. Add tiles A,B,C
3. Move navmesh bounds to tile 2 (the bounding box is bigger than the tile)
4. Rebuild navmesh

The navmesh is dynamic, and yes both levels contain the RecastNavMeshActor

I move the bounding box because the level has no limits and can grow infinitely.

---

<div class="post-metadata">

**Author:** ![BRGDemianLopez](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/brgdemianlopez/32/1052421_2.png) [@BRGDemianLopez](https://forums.unrealengine.com/u/BRGDemianLopez)\
**Post date:** [April 16, 2025, 3:49pm UTC](https://forums.unrealengine.com/t/rebuilding-dynamic-navmesh-via-c-stops-working-after-switching-levels/2459652/4 "2025-04-16T15:49:27Z")

</div>

@kitun All right, are you instancing the tile (level instancing), or are you loading it as a sublevel?

Can I see the code where you’re calling the navmesh rebuild? Are you waiting for everything to load/show before triggering the rebuild?

---

<div class="post-metadata">

**Author:** ![kitun](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@kitun](https://forums.unrealengine.com/u/kitun)\
**Post date:** [April 17, 2025, 5:59am UTC](https://forums.unrealengine.com/t/rebuilding-dynamic-navmesh-via-c-stops-working-after-switching-levels/2459652/5 "2025-04-17T05:59:43Z")

</div>

The tiles are simple actors, I’m adding them to the world via the GetWorld()-\>SpawnActor method. There is no sublevels or level instancing.

The code that calls for navmesh generation is just what i sent in the OP, there’s nothing more to it. Simply move the navmesh bounding volume and then call build on the navigation system.

About the method calls, they are called after some time of gameplay, only when player reaches certain triggers, so I’m pretty sure that it’s not something not being initialized.

The thing is, this works without issue if this is the first loaded level, so I’m guessing the logic works ok. It stops working only when i load a different level with a navmesh and return to it. (Both navmeshes have the same dynamic configuration btw).

---

<div class="post-metadata">

**Author:** ![Cykablatta](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Cykablatta](https://forums.unrealengine.com/u/Cykablatta)\
**Post date:** [July 1, 2025, 8:12am UTC](https://forums.unrealengine.com/t/rebuilding-dynamic-navmesh-via-c-stops-working-after-switching-levels/2459652/6 "2025-07-01T08:12:35Z")

</div>

@BRGDemianLopez Can i ask you something about it? Because I was trying to update/rebuilding my nav in runtime after map gen completed, but when I move and scale the navmesh so that it perfectly contains the entire map without excesses/defects, this is not triggering anything. It seems there’re no bp nodes that allow runtime nav rebuild, so I guess I’m forced to use C++, and I would use the same method used by @kitun , because I’m not able to code without visual, but I’ve not alternatives.

Let me know and thank you anyway!
