Download

Set Navigation Area Class

How do you set the Navigation Area Class for a Box Collision component in C++?

I’ve added the component to my class using the following.


Box = CreateDefaultSubobject<UBoxComponent>(TEXT("Box"));

When I create a Blueprint of my C++ class, the Box component has a section called Navigation in the Details panel. This section has a property called Area Class that is set to NavArea_Obstacle by default. I would like the default value to just be None. I know I can set it on the Blueprint, but I would rather set it in the C++ class constructor so I don’t have to remember to do it later when creating Blueprints from it.

I have found this on the Box component.


Box->AreaClass

Which is this in the ShapeComponent.h header.


/** Navigation area type (empty = default obstacle) */
UPROPERTY(EditAnywhere, Category = Navigation)
TSubclassOf<class UNavArea> AreaClass;

So this appears to be what I want. I just don’t know how to set it to None (which is one of the options in the Blueprint dropdown list).

I worked out that you can set it to one of the types defined in the NavArea_*.h header files. If you want to set it to None, just assign nullptr as the value. Really don’t know why I didn’t think to try that in the first place.

If you want to transform it into a walkable, use this:


 
 Box->AreaClass = FNavigationSystem::GetDefaultWalkableArea(); 

This post gave me an idea to solve another problem i had.