How to read current NavArea in which character is?

#Video Pic For You

I am doing what you are asking in this picture below!

The nav area closest to the AI unit is being highlighted as they move!

Here’s a gif of my AI using my custom Nav components finding a jumping path to its target using only C++, and a simple nav mesh volume in editor. There are no special helpers in the level! This was all calculated in C++ !

#Code, FindNearestPoly

In my custom UPathFollowComponent I wrote the following:

NavNodeRef UJoyPathFollowCompHighest::NavPoly_FindNearest(const FVector & Loc, const FVector & Extent)
{
	if(!MovementComp) return false;
	//~~~~~~~~~~~~~~~~~~
	
	//Agent Properties
	const FNavAgentProperties* AgentProperties = MovementComp->GetNavAgentProperties();
	if(!AgentProperties) return false;
	//~~~~~~~~~~~~~~~~~~
	
	const ANavigationData* NavData = (AgentProperties != NULL) ? GetNavDataForProps(*AgentProperties) : GetMainNavData(FNavigationSystem::DontCreate);
	 
	if (NavData == NULL)
	{
		NavData = GetMainNavData();
	}
	 
	const ARecastNavMesh* NavMesh = Cast<ARecastNavMesh>(NavData);
	if(!NavMesh)
	{
		ScreenMsg("UJoyPathFollowCompHighest::DrawNavTileBounds()>> Cast to recast nav mesh failed");
		return false;
	}
	
	return NavMesh->FindNearestPoly(Loc,Extent,NavData->GetDefaultQueryFilter());
}

#Recast

The focus of my code is that I had to cast the basic nav mesh ptr to ARecastNavMesh in order to access the desired function

:slight_smile:

#Extent

This determines how far above and below the point UE4 checks to find a valid nav area.

Enjoy!

#:heart:

Rama

3 Likes