Understanding PathFollowingComponent

There is hardly any documentation on how to handle the actual movement of a custom PathFollowComponent (applying the SetLocations/rotations/etc.). There is this tutorial by Rama but he doesn’t tell you where to even get the Controller to apply the location and rotation functions for movement. A new, community-hosted Unreal Engine Wiki - Announcements - Epic Developer Community Forums

I have a very simple barebones class for my own custom PathFollowingComponent because I want to be able to dictate where and how a character moves (speed/direction) along a certain path as it goes from path node to path node:

#include "Navigation/PathFollowingComponent.h"
#include "NaturalPathFollow.generated.h"

UCLASS()
class PUEBLOSIM_API UNaturalPathFollowComp : public UPathFollowingComponent
{
	GENERATED_BODY()
public:

	/** follow current path segment */
	virtual void FollowPathSegment(float DeltaTime) override;

	/** sets variables related to current move segment */
	virtual void SetMoveSegment(int32 SegmentStartIndex) override;

	/** check state of path following, update move segment if needed */
	virtual void UpdatePathSegment() override;
};

I already have an AIController class that uses this custom PathFollowingComponent and it is calling the 3 functions above successfuly. But I don’t know where to go from here. The UE4 documentation does not offer examples and the raw source is not very helpful. How do I go about from here getting the current node position, next node position, and the object in which to apply velocity to traverse through the path???

Hi there,

I was looking for a solution to one of my issues with using a customized UPathFollowingComponent (my functions don’t fire at all from the AIController, but I digress), and came across this question that I think I may be able to answer.

So the functions I found particularly useful are:

  • GetCurrentPathIndex();
  • GetNextPathIndex();

You can combine these with functions in FNavPathSharedPtr (FNavigationPath) by feeding the Index you obtained from the above functions:

  • GetSegmentDirection();
  • GetPathPointLocation();

With this information and the Pawn’s current velocity, etc, the AI Controller should be able to work out the appropriate inputs. If you’d like me to share my code, I’m more than happy to do so even though mine is embarassingly basic. :wink: