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

Sorry, the code above is what DIDN’T work (in the hopes someone could give me a hint). I will check out DrawDebugSolidPlane, this thing is just for level developers to visualize flow and active area sets in their levels.

This is how you get the full mesh data. Its basically one of Rama’s posts that I found, simplified to just the bits I needed and then a bit of digging around in the API to figure out what else I could use (GetPolysInTile)…

How to work around every single poly in the navmesh



void AAIDirectorPawn::GenerateFlowData(FVector Start, FVector End)
{
	UNavigationSystem* NavSys = GetWorld()->GetNavigationSystem();
	if (!NavSys)
		return;


	UNavigationPath* Path = // Magic sauce here;

	const ARecastNavMesh* NavMesh = Cast<ARecastNavMesh>(NavSys->GetMainNavData(FNavigationSystem::ECreateIfEmpty::Create));
	if (NavMesh == nullptr)
		return;


	TArray<FNavPoly> TilePolys;
	for (int32 TileIndex = 0; TileIndex < NavMesh->GetNavMeshTilesCount(); TileIndex++)
	{

		//CHECK IS VALID FIRST OR WILL CRASH!!!
		// use continue in case the valid polys are not stored sequentially
		if (!NavMesh->GetNavMeshTileBounds(TileIndex).IsValid)
			continue;

		NavMesh->GetPolysInTile(TileIndex, TilePolys);
		//Add them all!
		for (int32 Idx = 0; Idx < TilePolys.Num(); Idx++)
		{
		        // Magic sauce to calculate flow value of polygon here
			NavFlowData.AddUnique(PolyData);
		}
	}

	NavFlowData.Sort(AAIDirectorPawn::FlowSort);

}


A simple debug function to render it out as wireframe



bool AAIDirectorPawn::RenderFlowWireframe()
{
	UNavigationSystem* NavSys = GetWorld()->GetNavigationSystem();
	if (!NavSys)
		return true;
	
	const ARecastNavMesh* NavMesh = Cast<ARecastNavMesh>(NavSys->GetMainNavData(FNavigationSystem::ECreateIfEmpty::Create));
	if (NavMesh == nullptr)
		return true;

	TArray<FVector> Verts;
	for (auto& PolyData : NavFlowData)
	{
		Verts.Reset();
		NavMesh->GetPolyVerts(PolyData.PolyRef, Verts);

		//const FColor TestPolyColor = FColor::Green;

		//Lerp Color
		FLinearColor LinearColor = FMath::Lerp(FLinearColor::Red, FLinearColor::Blue, PolyData.FlowValue);
		FColor TestPolyColor = LinearColor.ToFColor(true);
		for (int32 VertIdx = 0; VertIdx < Verts.Num() - 2; VertIdx++)
		{
			const FVector Pt0 = Verts[VertIdx];
			const FVector Pt1 = Verts(VertIdx + 1)];
			const FVector Pt2 = Verts(VertIdx + 2)];

			DrawDebugLine(GetWorld(), Pt0 + 10.0f * 0.5f, Pt1 + 10.0f * 0.5f, TestPolyColor, false
				, /*LifeTime*/-1.f, /*DepthPriority*/0
				, /*Thickness*/10.0f);

			DrawDebugLine(GetWorld(), Pt1 + 10.0f * 0.5f, Pt2 + 10.0f * 0.5f, TestPolyColor, false
				, /*LifeTime*/-1.f, /*DepthPriority*/0
				, /*Thickness*/10.0f);

			DrawDebugLine(GetWorld(), Pt2 + 10.0f * 0.5f, Pt0 + 10.0f * 0.5f, TestPolyColor, false
				, /*LifeTime*/-1.f, /*DepthPriority*/0
				, /*Thickness*/10.0f);
		}

		const FVector Pt0 = Verts[0];
		const FVector Pt1 = Verts(Verts.Num() - 2)];
		const FVector Pt2 = Verts(Verts.Num() - 1)];

		DrawDebugLine(GetWorld(), Pt0 + 10.0f * 0.5f, Pt1 + 10.0f * 0.5f, TestPolyColor, false
			, /*LifeTime*/-1.f, /*DepthPriority*/0
			, /*Thickness*/10.0f);

		DrawDebugLine(GetWorld(), Pt1 + 10.0f * 0.5f, Pt2 + 10.0f * 0.5f, TestPolyColor, false
			, /*LifeTime*/-1.f, /*DepthPriority*/0
			, /*Thickness*/10.0f);

		DrawDebugLine(GetWorld(), Pt2 + 10.0f * 0.5f, Pt0 + 10.0f * 0.5f, TestPolyColor, false
			, /*LifeTime*/-1.f, /*DepthPriority*/0
			, /*Thickness*/10.0f);
	}
	return false;
}