Pathfinding test use custom cost

Hello,

I’ve successfully modified the cost function (GetCost(…)) in the pathfinding algorithm and it does work. This functions gets called when the AI needs to move from one point to another. However, when I add an Environment Query with a pathfinding test, it doesnt get called. This pathfinding tests uses the default cost.

Does anyone know how to fix this to make the pathfinding use my custom navmesh and filter and thus call my custom GetCost function?

Thanks.

After fighting for a while and looking at the source code of UE 4 I found the solution.

First of all, create a custom class that inherits from UNavigationQueryFilter, lets call it UMyNavigationQueryFilter. Then, override the InitializeFilter method:

  virtual void InitializeFilter(const ANavigationData& NavData, FNavigationQueryFilter& Filter) const override;

If you look at the source code this is the implementation of this method:

void UMyNavigationQueryFilter::InitializeFilter(const ANavigationData& NavData, FNavigationQueryFilter& Filter) const
{
#if WITH_RECAST

		Filter.SetFilterImplementation(dynamic_cast<const INavigationQueryFilterInterface*>(ARecastNavMesh::GetNamedFilter(ERecastNamedFilter::FilterOutAreas)));
	

#endif // WITH_RECAST

	Super::InitializeFilter(NavData, Filter);
}

So, to use your custom filter class just replace the SetFilterImplementation call by:

		Filter.SetFilterType<FRecastQueryFilter_Example>();

Where FRecastQueryFilter_Example is the name of your filter class that implements INavigationQueryFilterInterface, dtQueryFilter_Example.

Finally, dont forget to add your filter class in the EQS Test.