# Creating/Providing a path for a MoveRequest

**URL:** <https://forums.unrealengine.com/t/creating-providing-a-path-for-a-moverequest/458288>\
**Category:** AI\
**Tags:** pathfinding, Navigation, moveto, unreal-engine, path, question\
**Created:** [November 11, 2019, 7:59pm UTC](https://forums.unrealengine.com/t/creating-providing-a-path-for-a-moverequest/458288 "2019-11-11T19:59:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brannigan](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Brannigan](https://forums.unrealengine.com/u/Brannigan)\
**Post date:** [November 11, 2019, 5:08pm UTC](https://forums.unrealengine.com/t/creating-providing-a-path-for-a-moverequest/458288/1 "2019-11-11T17:08:25Z")

</div>

Solved it.

For anyone stumbling upon creating own path, Make sure after you have the pathpoints set up, you have to FNavigationPath-\>MarkReady() and possibly also FNavigationPath-\>DoneUpdating(ENavPathUpdateType).

Otherwise, path-\>IsValid() returns false. Note that’s the FNavigationPath::IsValid, not FNavPathSharedPtr::isValid().

---

<div class="post-metadata">

**Author:** ![Brannigan](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Brannigan](https://forums.unrealengine.com/u/Brannigan)\
**Post date:** [November 11, 2019, 7:59pm UTC](https://forums.unrealengine.com/t/creating-providing-a-path-for-a-moverequest/458288/2 "2019-11-11T19:59:19Z")

</div>

I was wondering what the proper way to create an FNavPathSharedPtr/FNavigationPath would be, given an array of pathpoints/FVectors.

Currently, I have an FNavPathSharedPtr that I pass into a generic MoveTo. In that MoveTo, I create a new FNavigationPath then add FNavPathPoints to the array (which I know is valid as there are examples of this in source code)

Here is how I do that:

```
//Now to remove all other points in outpath
//Need the total num as we will remove points from end of array during iteration
int num = PathResult.Path->GetPathPoints().Num();

targetPath = MakeShareable(new FNavigationPath());
targetPath->SetNavigationDataUsed(PathResult.Path->GetNavigationDataUsed());
targetPath->SetTimeStamp(GetWorld()->GetTimeSeconds());

//Remove pathpoints from last index in array down to the last index used + 1 (which is the new end of array)
for (int d = num - 1; d > i + 1; d--)
{
	//Target path will be end of PathResult.Path down to middle, which will provide target with a predetermined path to middle point
	targetPath->GetPathPoints().Add(PathResult.Path->GetPathPoints()[d]);

	PathResult.Path->GetPathPoints().RemoveAt(d);
	UE_LOG(LogAIControllerBase, Log, TEXT("Removing at %d, last index is %d. AAIController_Base::FindPathforMoveRequestToTarget()"), d, num - 1);
}
				
//Done to ensure AI navigates to new goal location over old goal
MoveRequest.UpdateGoalLocation(middle);

//i is the middle path point, which is not touched by the for loop since it becomes the new endpoint
FNavPathPoint point = PathResult.Path->GetPathPoints()[i];
point.Location = middle;
targetPath->GetPathPoints().Add(point);
targetPath->SetIsPartial(false);
UE_LOG(LogAIControllerBase, Log, TEXT("Location of last index in TargetPath is %s while middle is %s. AAIController_Base::FindPathforMoveRequestToTarget()"), *targetPath->GetPathPoints().Last().Location.ToString(), *middle.ToString());

OutPath = PathResult.Path;

//Make sure to update query for path
Query.EndLocation = middle;

//If not set, goal location is original from move call and on navPathEvent::NavigationUpdated the agent will repath to original goal location
Query.SetPathInstanceToUpdate(PathResult.Path);
OutPath->SetQueryData(Query);

//for target path, must update query path data for same reason as above, but with different path
Query.SetPathInstanceToUpdate(targetPath);
targetPath->SetQueryData(Query);

```

Passing the above targetPath into a custom MoveTo, it is valid when I check and I also pass it new Query data built of a new MoveRequest.

But checking the visual logger, shortly after the custom MoveTo is called, I see that the path actually states that it’s invalid due to path being partial, and the PathFollowingComponent-\>RequestMove() times out.

For what reasons could the path invalidate from AIController-\>MoveTo to PathFollowingComponent-\>RequestMove?

Here are two images from the visual logger

 ![292175-visualloggerprerequest.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/1/c/01ca850eedefcaf21802e07cb31958d76885fc59.png)

 ![292176-visualloggerpostrequest.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/c/0/cc0428980f3bb719b211beb424a61c11fb967798.png)

---

<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:** [March 9, 2020, 6:51pm UTC](https://forums.unrealengine.com/t/creating-providing-a-path-for-a-moverequest/458288/3 "2020-03-09T18:51:55Z")

</div>

Thanks, ISpam Its really help.
