How to Influence Exact Path Following Behavior
Hi there!
As gif above shows there is a way to modify standard UE4 pathing via C++ to introduce customized path following behavior without rewriting the whole system.
In gif above I am telling the unit how to jump from one nav mesh piece to another using only C++ (nothing was placed in the editor other than basic nav mesh, and I can add new level geometry any time)
You need to do several things
- Have your own Custom ai controller (extends AAIController)
2. Tell ai controller to use custom path following component, which extends the base UE4 class
Here's the code for that, you just modify the constructor
```
// UJoyPathFollowComp is used here!
AJoyController::AJoyController(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer.SetDefaultSubobjectClass<**UJoyPathFollowComp**>(TEXT("PathFollowingComponent")))
{
```
- Make sure your build.cs is including AIModule as part of your dependencies
PublicDependencyModuleNames.AddRange(new string] {
"Core",
"CoreUObject",
"Engine",
"InputCore" ,
"Landscape",
"UMG",
"PhysX", "APEX",
"AIModule" //<~~~~~~
});
- Override these functions in your custom PathFollowingComponent!
Especially **FollowPathSegment **!
This is where you can take control of exact pathing methods!
//~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Per Tick Modification of Path Following
// this is how you really customize
// how units follow the path!
/** 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;
**Video Result**
Using the above method is how I made custom C++ Jump pathing calculations that dont need any in-editor additions to the level, just the basic nav mesh volume.
https://www..com/watch?v=0GX-1x-wACI
**More of my customized C++ AI Pathing Videos**
https://forums.unrealengine.com/showthread.php?25410--s-Multi-Threaded-Dynamic-Pathing-System-Full-Physics-Support&p=129896&viewfull=1#post129896
:)
PS:
turned this into a wiki here
https://wiki.unrealengine.com/AI_Navigation_in_C%2B%2B,_Customize_Path_Following_Every_Tick