How i set my My Custom PathFollowing Component?

Hi.
I inherited from UPathFollowingComponent now I want force AI to use my PathFollowingComponent but I can’t, this is My code :

MyPathFollowingComponenet = NewObject<UCustomPathFollowingComponent>(this, TEXT("MyPathFollowing"));

SetPathFollowingComponent(MyPathFollowingComponenet);

but when I do that my AI creates two PathFollowingComponent :

319049-path.jpg

And it only uses the old PathFollowingComponent, not the new one.

anyone know the correct way to set UPathFollowingComponent for AIController?

To override a component class you need to use ObjectInitializer.SetDefaultSubobjectClass in the constructor of your actor.

Example:

// In header file

public:
  	AMyAIController(const FObjectInitializer& ObjectInitializer = FObjectInitializer::Get());

In cpp file:

AMyAIController::AMyAIController(const FObjectInitializer& ObjectInitializer) :
Super(ObjectInitializer.SetDefaultSubobjectClass<UCustomPathFollowingComponent>(TEXT("PathFollowingComponent")))

Where the name is the registered name of the component.