Change defaultQueryFilter implementation (NavMesh)

Hey, I am trying to modify the filter of the navmesh. To do that I’ve created a custom filter FRecastQueryFilter_Example and a custom navmesh AMyRecastNavMesh and then in the constructor of AMyRecastNavMesh I assign the implementation of the DefaultQueryFilter to my FRecastQueryFilter_Example. Then the DefaultQueryFilter changes.

The problem is that somewhere in the Unreal Code, the DefaultQueryFilter is changed back to the default implementation again, because when I call any other function of my navmesh I can see the value of the DefaultQueryFilter is equal to FRecastQueryFilter instead of FRecastQueryFilter_Example. I’ve tried doing a searchand debug of the SetFilterImplementationfunction and of the assignments to theDefaultQueryFilter` but didn’t find the problem.

Does anyone know where does this change happens and/or how to solve it?


MyRecastNavMesh.h

 class SHOOTERGAME_API FRecastQueryFilter_Example : public INavigationQueryFilterInterface, public dtQueryFilter_Example {
 //...
 };

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

  public:
        FRecastQueryFilter_Example DefaultNavFilter;

        AMyRecastNavMesh(const FObjectInitializer& ObjectInitializer);

        void SetupCustomNavFilter();
   };

MyRecastNavMesh.cpp
AMyRecastNavMesh::AMyRecastNavMesh(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{
	TSharedPtr<const FNavigationQueryFilter> QueryFilterBefore = GetDefaultQueryFilter();

	if (DefaultQueryFilter.IsValid())
	{
		DefaultQueryFilter->SetFilterImplementation(dynamic_cast<const INavigationQueryFilterInterface*>(&DefaultNavFilter));
	}
	TSharedPtr<const FNavigationQueryFilter> QueryFilterAfter = GetDefaultQueryFilter();
}

Moving the function SetupCustomNavFilter to inside the BeginPlay() solved the problem.