# How i set my My Custom PathFollowing Component?

**URL:** <https://forums.unrealengine.com/t/how-i-set-my-my-custom-pathfollowing-component/473089>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [October 17, 2020, 11:59pm UTC](https://forums.unrealengine.com/t/how-i-set-my-my-custom-pathfollowing-component/473089 "2020-10-17T23:59:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![AAriyAA](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AAriyAA](https://forums.unrealengine.com/u/AAriyAA)\
**Post date:** [October 17, 2020, 11:59pm UTC](https://forums.unrealengine.com/t/how-i-set-my-my-custom-pathfollowing-component/473089/1 "2020-10-17T23:59:39Z")

</div>

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](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/6/1/86117db558a198ec47d74d6db0a432bc377d3126.jpeg)

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

anyone know the correct way to set UPathFollowingComponent for AIController?

---

<div class="post-metadata">

**Author:** ![FunGames55](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/fungames55/32/710746_2.png) [@FunGames55](https://forums.unrealengine.com/u/FunGames55)\
**Post date:** [May 29, 2024, 11:41pm UTC](https://forums.unrealengine.com/t/how-i-set-my-my-custom-pathfollowing-component/473089/2 "2024-05-29T23:41:16Z")

</div>

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

Example:

// In header file

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

```

In cpp file:

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

```

Where the name is the registered name of the component.
