How do I spawn a Nav Modifier within the Editor in C++?

Hi all,

I want to create a tool that allows me to string together nav modifiers on a map in the editor. Think of the spline component but I’m just making rectangular nav modifiers that touch tip to tail based of the points you’ve created. I’ve already set up a NavRoad component and NavRoad component visualizer, but I’m not sure how to actually spawn an object in the editor that can affect the nav mesh with a given custom UNavArea. Does anyone know how I can do this?

I’ve read that you can’t just spawn regular nav modifiers so I created my own class that I want to spawn, but I’m not sure what I should derive from for them to affect the nav mesh.

This is all done in C++ and any help would be really appreciated!!

Right now, I’m deriving from a UBoxComponent and overriding the GetNavigationData() and GetNavigationBounds() functions that come from the INavRelevantInterface. Also in my constructor i’m setting bNavigationRelevant and bCanEverAffectNavigation to true. Also I’m calling UpdateComponentData(*this) in PostEditUndo and PostEditChangeProperty. I am also making sure, in the constructor, to set what AreaClasss i want to use for the box. But the nav mesh doesn’t change or detect the box component.

Mieszko said to try to follow how the nav modifier does things, here: https://answers.unrealengine.com/questions/498659/how-to-spawn-a-navmodifiervolume-in-c.html.

I got this to work for an actor that I gave the INavRelevantInterface, but not for a component. Also just in case you were wondering UBoxComponent does have that interface.

So still stuck. Does anyone know about UNavModifierComponent or if that is useful to me? Or if I’m missing something with the UBoxComponent?

So I was able to do this by having a base AActor class that holds a USceneComponent, which deals with spawning all the UBoxComponents. I have the USceneComponent so I can attach a component visualizer attached to the hole thing. The AActor also holds a UNavModfierComponent which basically looks at all the volumes connected to the AActor (the UBoxComponents) and modifies the nav mesh based on them.

Also something to note is that when you create the UBoxComponents within the editor, in order to make them visible and actually connected to the AActors component list, you have to call RegisterComponent() on the newly created UBoxComponent.

If you have any questions feel free to comment and ask

So, you make and redefined new NavModifierVolume by overriding GetNavigationData() and GetNavigationBounds() in INavRelevantInterface.h right?