Long long ago, in the days of like Unreal 2 and 3, when you were doing some path following movements, you would receive an event called, I think, PrepareForMove, something like that, that would have the information about the current chunk of the path move.
I want to be able to do some examination of that specific move, and perhaps define some custom parameters for that move (such as setting the character to run if it’s a long range move, then restore to walk speed when it’s a shorter range). I can’t really do this at the move call, because the move call does the pathfinding, and i want this to only affect certain pieces of the path, so I want to do this checking for each move made on that path, not for the entire move request.
Any ideas on how to achieve something like that? don’t care if it’s native or blueprint.
There are two functions that should give you what you need. For regular path following it’s
UPathFollowingComponent::SetMoveSegment, which gets called whenever you arrive at the next point in the path. You can use it like this:
void UMyPathFollowingComponent::SetMoveSegment(int32 SegmentStartIndex)
// all the points on the currernt path
const TArray<FNavPathPoint>& Points = Path->GetPathPoints();
// index into the current nav point
const FNavPathPoint& SegmentStart = Points[MoveSegmentStartIndex];
// index into the next path point
const FNavPathPoint& SegmentEnd = Points[MoveSegmentEndIndex];
This works with nav mesh proxies as well as regular navmesh wayfinding.
If you’re using Detour Crowd you can override
UCrowdFollowingComponent::OnNavNodeChanged. The other function won’t get called for these kinds of path following components. The data handling is a little different, too:
void UMyCrowdFollowingComponent::OnNavNodeChanged(NavNodeRef NewPolyRef, NavNodeRef PrevPolyRef, int32 CorridorSize)
Super::OnNavNodeChanged(NewPolyRef, PrevPolyRef, CorridorSize);
FVector Start, End;
FNavMeshPath* NavMeshPath = Path->CastPath<FNavMeshPath>();
// this one fetches the current and the next point's location
// and stores them in Start & End
GetNavNodeSegments(NavMeshPath, Start, End);
This, too, works with navigation on the mesh as well as between points of a nav mesh proxy.
Ah, brilliant, I’ve been reading through AIController and PathFollowingComponent for much of the day looking to see if there was something hidden in here to support, it looks like I could use something like overriding this to pass the move info up into a better place (like a blueprint implementation function) where i could decide to take some action (slow down, speed up, abort move, etc) and go from there.