# How can I edit the path that tells an AI character where to move?

**URL:** <https://forums.unrealengine.com/t/how-can-i-edit-the-path-that-tells-an-ai-character-where-to-move/315436>\
**Category:** AI\
**Tags:** pathfinding, Navigation, custom-component, unreal-engine, CPP, question\
**Created:** [April 17, 2015, 5:21pm UTC](https://forums.unrealengine.com/t/how-can-i-edit-the-path-that-tells-an-ai-character-where-to-move/315436 "2015-04-17T17:21:58Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![jechli\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@jechli\_1](https://forums.unrealengine.com/u/jechli_1)\
**Post date:** [April 17, 2015, 5:21pm UTC](https://forums.unrealengine.com/t/how-can-i-edit-the-path-that-tells-an-ai-character-where-to-move/315436/1 "2015-04-17T17:21:58Z")

</div>

I’m currently trying to create a custom Path Following Component for my AI character so that I can edit the path that it tells the character to go. The reason I am doing this is because I want to create a smoother path for the character (when changing directions and turning around corners). I am thinking of adding a few more points around the target location to create a curved path, but I’m not really sure where I can override the path points in the path following component. This is all done in C++.

If there is another way to solve this problem (smoothing out turns for AI characters) I would be willing to try something else as well.

---

<div class="post-metadata">

**Author:** ![MieszkoZ](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MieszkoZ](https://forums.unrealengine.com/u/MieszkoZ)\
**Post date:** [April 19, 2015, 9:12pm UTC](https://forums.unrealengine.com/t/how-can-i-edit-the-path-that-tells-an-ai-character-where-to-move/315436/2 "2015-04-19T21:12:59Z")

</div>

I can suggest deriving a class from `PathFollowingComponent` and overriding `RequestMove` and `UpdateMove`. In those functions you can post-process new path before passing it over to the super call.

Let me know if you run into issues while trying this out.

Cheers,

–mieszko

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [April 21, 2015, 8:50am UTC](https://forums.unrealengine.com/t/how-can-i-edit-the-path-that-tells-an-ai-character-where-to-move/315436/3 "2015-04-21T08:50:49Z")

</div>

#More Info and a Wiki

To expand on Mieszko’s (Hi Miezsko!) answer,

I have a wiki with code samples on the subject of custom UE4 AI pathing here!

**Wiki on Custom AI Pathing in UE4**

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...

Rama

---

<div class="post-metadata">

**Author:** ![jechli\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@jechli\_1](https://forums.unrealengine.com/u/jechli_1)\
**Post date:** [June 3, 2015, 8:37pm UTC](https://forums.unrealengine.com/t/how-can-i-edit-the-path-that-tells-an-ai-character-where-to-move/315436/4 "2015-06-03T20:37:55Z")

</div>

Hey guys, thanks for the reply! I’ve put this task off for a bit but now I’m back at it.

I’ve attempted to make some changes in SetMoveSegment() and FollowPathSegment(), and I’ve got my path following component initialized in my custom ai controller (I think):

```
ASKIMEGController::ASKIMEGController(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer.SetDefaultSubobjectClass<USKIMEGPathFollowingComponent>(TEXT("MEGPathFollowingComponent")))

```

I ran the game in the editor and everything worked as if I never changed anything. Then I ran it in debugging editor mode, and placed breakpoints in those two overridden functions. After running my AI in the game for a few minutes the breakpoints were never triggered, meaning my path following component isn’t being run in the first place. Am I initializing it incorrectly?

---

<div class="post-metadata">

**Author:** ![kamrann](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@kamrann](https://forums.unrealengine.com/u/kamrann)\
**Post date:** [June 4, 2015, 7:42am UTC](https://forums.unrealengine.com/t/how-can-i-edit-the-path-that-tells-an-ai-character-where-to-move/315436/5 "2015-06-04T07:42:00Z")

</div>

The name passed into `SetDefaultSubobjectClass` should match up with the name that the parent class (in this case AAIController) uses when creating the component. It’s a bid fiddly, as far as I know currently you just have to check the engine source code to find out. So anyway, you need to change it to:

```
ObjectInitializer.SetDefaultSubobjectClass<USKIMEGPathFollowingComponent>(TEXT("PathFollowingComponent"))
```

---

<div class="post-metadata">

**Author:** ![ond\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ond\_1](https://forums.unrealengine.com/u/ond_1)\
**Post date:** [July 12, 2017, 1:23pm UTC](https://forums.unrealengine.com/t/how-can-i-edit-the-path-that-tells-an-ai-character-where-to-move/315436/6 "2017-07-12T13:23:11Z")

</div>

So I’ve been tinkering around with `RequestMove` and `UpdateMove`, or well `HandlePathUpdateEvent` now actually. I’m not quite sure how to add points to the InPath though… I’ve been looking at `FMetaNavMeshPath` and creating one and passing it as the InPath to my Super. Is this the right, or even a valid way to go about it? The description of `FMetaNavMeshPath` sounds like what i need, since it talks about guided paths with past set waypoints

---

<div class="post-metadata">

**Author:** ![ond\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ond\_1](https://forums.unrealengine.com/u/ond_1)\
**Post date:** [July 13, 2017, 12:44pm UTC](https://forums.unrealengine.com/t/how-can-i-edit-the-path-that-tells-an-ai-character-where-to-move/315436/7 "2017-07-13T12:44:02Z")

</div>

To answer my own question a bit. Yes this works, once i finally managed to pass `FMetaNavMeshPath` as a `FNavPathSharedPtr` which i did by first setting it up as a `TSharedPtr` like so:

```
TSharedPtr<FMetaNavMeshPath, ESPMode::ThreadSafe> MetaPathPtr(new FMetaNavMeshPath(Waypoints, *Controller));

```

…bla bla bla code here bla bla…

```
InPath = FNavPathSharedPtr(MetaPathPtr);

```

Maybe there’s an easier way to go about it? but `FNavPathSharedPtr` doesn’t seem to have a suitable constructor for `FMetaNavMeshPath`

---

<div class="post-metadata">

**Author:** ![ZioYuri78](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/zioyuri78/32/1194615_2.png) [@ZioYuri78](https://forums.unrealengine.com/u/ZioYuri78)\
**Post date:** [July 18, 2018, 2:01pm UTC](https://forums.unrealengine.com/t/how-can-i-edit-the-path-that-tells-an-ai-character-where-to-move/315436/8 "2018-07-18T14:01:48Z")

</div>

Hey, just a question, which FMetaNavMeshPath constructor are you using? Because i’m trying to use the “TArray, AController” version but compiler still throw me the following error:

```
error C2664: 'FMetaNavMeshPath::FMetaNavMeshPath(FMetaNavMeshPath &&)': cannot convert argument 1 from 'TArray<FVector,FDefaultAllocator>' to 'const TArray<FMetaPathWayPoint,FDefaultAllocator> &'

```

looks like he want to use only this constructor

```
FMetaNavMeshPath(const TArray<FMetaPathWayPoint>& InWaypoints, const ANavigationData& NavData);

```

instead of

```
FMetaNavMeshPath(const TArray& InWaypoints, const AController& Owner);

```

any idea?

Snippet of my testing code here:

```
TArray<FVector> Locations;
Locations.Add(FVector(250.f, 250.f, 0.f));
Locations.Add(FVector(450.f, -250.f, 0.f));
Locations.Add(FVector(650.f, 250.f, 0.f));
	
AController* Controller = Cast<AController>(GetOwner());
FMetaNavMeshPath *MetaNavMeshPath = new FMetaNavMeshPath(Locations, Controller);

TSharedPtr<FMetaNavMeshPath, ESPMode::ThreadSafe> MetaPathPtr(MetaNavMeshPath);

InPath = FNavPathSharedPtr(MetaPathPtr);
```

---

<div class="post-metadata">

**Author:** ![kamrann](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@kamrann](https://forums.unrealengine.com/u/kamrann)\
**Post date:** [July 18, 2018, 3:32pm UTC](https://forums.unrealengine.com/t/how-can-i-edit-the-path-that-tells-an-ai-character-where-to-move/315436/9 "2018-07-18T15:32:13Z")

</div>

You need to dereference your pointer. It’s not common in the engine, but some of the AI code has (sensibly) started to use references instead of pointers to objects in function parameters.  
`FMetaNavMeshPath(Locations, *Controller);`

---

<div class="post-metadata">

**Author:** ![ZioYuri78](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/zioyuri78/32/1194615_2.png) [@ZioYuri78](https://forums.unrealengine.com/u/ZioYuri78)\
**Post date:** [July 18, 2018, 4:49pm UTC](https://forums.unrealengine.com/t/how-can-i-edit-the-path-that-tells-an-ai-character-where-to-move/315436/10 "2018-07-18T16:49:22Z")

</div>

Holy cow! That was simple! Thanks a lot 🙂
