Custom Recastnavmesh. FindPath method

Hi,

I want to modify the costs of the different nodes of the navmesh. To do so, I am overriding the RecastNavMesh and the FindPath method. I’ve also modified the DefaultEngine.ini file. Everthing compiles but I am missing something. When I run the game everthing works correctly and it shouldn’t because the FindPath implementation is empty. The UE4 log is also empty. I’ve been looking for any docs or tutorials but I didn’t find anything…

I’ve also tried to assign FindPath method to FindPathImplementation attr of MyRecastNavMesh but FPathFindingResult is not compatible with FFindPathPtr

Any help will be useful.

Thanks!


The header file MyRecastNavMesh.h:

UCLASS()
class TOPDOWNCPP_API AMyRecastNavMesh : public ARecastNavMesh
{
GENERATED_BODY()

public:

FPathFindingResult FindPath(const FNavAgentProperties & AgentProperties, const FPathFindingQuery & Query);
};

And in the MyRecastNavMesh.cpp I’ve implemented a dummy behavior:

FPathFindingResult AMyRecastNavMesh::FindPath(const FNavAgentProperties& AgentProperties, const  FPathFindingQuery& Query)
{
UE_LOG(LogTemp, Warning, TEXT("AMyRecastNavMesh::FindPath"));

FPathFindingResult Result;
return Result;
}

DefaultEngine.ini:

...
[/Script/Engine.NavigationSystem]
RequiredNavigationDataClassNames="/Script/MyProjectName.MyRecastNavMesh"

Solution

It seems that you haven’t declared your FindPath as static in MyRecastNavMesh.h, you need to declare your function as such:

static FPathFindingResult FindPath(const FNavAgentProperties& AgentProperties, const FPathFindingQuery& Query);

Reason

In your case, you’re attempting to point to a member function, which requires the FFindPathPtr to be declared as (note the extra AMyRecastNavMesh::):

typedef FPathFindingResult (AMyRecastNavMesh::*FFindPathPtr)(const FNavAgentProperties& AgentProperties, const FPathFindingQuery& Query);

Instead of:

typedef FPathFindingResult (*FFindPathPtr)(const FNavAgentProperties& AgentProperties, const FPathFindingQuery& Query);

Static members are treated by C++ as plain functions, instead of member functions, hence why you would get the following error:

error C2440: '=': cannot convert from 'FPathFindingResult (__cdecl AMyRecastNavMesh::* )(const FNavAgentProperties &,const FPathFindingQuery &)' to 'ANavigationData::FFindPathPtr'

You can read up more about Pointer to Member functions here.

Perfect answer. I misunderstood some concepts of C++. Now it is more clear, Thanks!