my .cpp
#include "XXXXPathfinding.h"
#include "Engine/Engine.h"
#include "Runtime/Engine/Classes/AI/Navigation/NavigationSystem.h"
#include "Runtime/Engine/Classes/AI/Navigation/RecastNavMesh.h"
bool UXXXXPathfinding::GetAllPolys(TArray& Polys)
{
if (!MovementComp) return false;
//~~~~~~~~~~~~~~~~~~
//Get Nav Data
const ANavigationData* NavData = GetMainNavData(FNavigationSystem::DontCreate);
const ARecastNavMesh* NavMesh = Cast<ARecastNavMesh>(NavData);
if (!NavMesh)
{
return false;
}
TArray<FNavPoly> EachPolys;
for (int32 v = 0; v < NavMesh->GetNavMeshTilesCount(); v++)
{
//CHECK IS VALID FIRST OR WILL CRASH!!!
// 256 entries but only few are valid!
// using continue in case the valid polys are not stored sequentially!
if (!TileIsValid(NavMesh, v))
{
continue;
}
NavMesh->GetPolysInTile(v, EachPolys);
}
//Add them all!
for (int32 v = 0; v < EachPolys.Num(); v++)
{
Polys.Add(EachPolys[v].Ref);
}
}
void UXXXXPathfinding::BeginPlay()
{
}