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