How to render your own navmesh debug? RAMA/EPIC help please?

You know the engine has a navigation viewmode already? If you’re in the editor (and navigation is set up) pressing ‘P’ (default) or clicking the “Show” button (next to “Perspective” and “Lit” or whatever viewmode you’re in currently) and then selecting “Navigation” in the viewport will show it. I guess you can manually trigger the same action from code. Although I didn’t look at all of it (whether it’s possible to access everything required in both editor and ingame) but if you’re interested I’d suggest starting with <path/to/UE4>/Engine/Source/Editor/LevelEditor/Public/LevelViewportActions.h and <path/to/UE4>/Engine/Source/Editor/LevelEditor/Private/LevelViewportActions.cpp (FLevelViewportCommands::RegisterCommands and FLevelViewportCommands::ShowFlagCommands). From here you can find the existing navigation rendering code and probably call it from your code.

Edit: I think I found it, check out UNavigationPath::DrawDebug. It is protected but you can get access to SharedPath which is used by it. All you need is a Canvas…
See files Engine/Source/Runtime/Engine/Classes/AI/Navigation/NavigationPath.h Engine/Source/Runtime/Engine/Classes/AI/Navigation/NavigationPath.cpp and Engine/Source/Runtime/Engine/Classes/AI/Navigation/NavigationData.h

So your code would look something like this (untested):


UCanvas* Canvas = <Get Canvas from somewhere, viewport client, HUD, ...?>; //isn't even used in FNavigationPath::DebugDraw so may as well be 'nullptr'
UNagivationPath* NavigationPath = <Get UNagivationPath from somewhere, TObjectIterator, ...?>;
FColor PathColor = FColor::White; //normally NavigationPath->DebugDrawingColor, initialized to White in UNagivationPath::UNagivationPath and set in UNavigationPath::EnableDebugDrawing() which is never called from anywhere as far as I can tell (searching entire solution came up with two things only: definition and declaration.
bool bPersistent = false; //default used in UNavigationPath
const uint32 NextPathPointIndex = 0; //function argument which defaults to 0 if not passed in

if (NavigationPath)
{
	FNavPathSharedPtr SharedPath = NavigationPath->GetPath();
	if (SharedPath.IsValid())
	{
		SharedPath->DebugDraw(SharedPath->GetNavigationDataUsed(), PathColor, Canvas, bPersistent, NextPathPointIndex);
	}
}