x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

How can I edit the path that tells an AI character where to move?

I'm currently trying to create a custom Path Following Component for my AI character so that I can edit the path that it tells the character to go. The reason I am doing this is because I want to create a smoother path for the character (when changing directions and turning around corners). I am thinking of adding a few more points around the target location to create a curved path, but I'm not really sure where I can override the path points in the path following component. This is all done in C++.

If there is another way to solve this problem (smoothing out turns for AI characters) I would be willing to try something else as well.

Product Version: Not Selected
Tags:
more ▼

asked Apr 17 '15 at 05:21 PM in C++ Programming

avatar image

jechli
145 22 26 84

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

I can suggest deriving a class from PathFollowingComponent and overriding RequestMove and UpdateMove. In those functions you can post-process new path before passing it over to the super call.

Let me know if you run into issues while trying this out.

Cheers,

--mieszko

more ▼

answered Apr 19 '15 at 09:12 PM

avatar image

MieszkoZ STAFF
7.3k 223 57 412

avatar image ond_ Jul 12 '17 at 01:23 PM

So I've been tinkering around with RequestMove and UpdateMove, or well HandlePathUpdateEvent now actually. I'm not quite sure how to add points to the InPath though... I've been looking at FMetaNavMeshPath and creating one and passing it as the InPath to my Super. Is this the right, or even a valid way to go about it? The description of FMetaNavMeshPath sounds like what i need, since it talks about guided paths with past set waypoints

avatar image ond_ Jul 13 '17 at 12:44 PM

To answer my own question a bit. Yes this works, once i finally managed to pass FMetaNavMeshPath as a FNavPathSharedPtr which i did by first setting it up as a TSharedPtr like so:

 TSharedPtr<FMetaNavMeshPath, ESPMode::ThreadSafe> MetaPathPtr(new FMetaNavMeshPath(Waypoints, *Controller));

....bla bla bla code here bla bla...

 InPath = FNavPathSharedPtr(MetaPathPtr);

Maybe there's an easier way to go about it? but FNavPathSharedPtr doesn't seem to have a suitable constructor for FMetaNavMeshPath

avatar image ZioYuri78 Jul 18 '18 at 02:01 PM

Hey, just a question, which FMetaNavMeshPath constructor are you using? Because i'm trying to use the "TArray, AController" version but compiler still throw me the following error:

 error C2664: 'FMetaNavMeshPath::FMetaNavMeshPath(FMetaNavMeshPath &&)': cannot convert argument 1 from 'TArray<FVector,FDefaultAllocator>' to 'const TArray<FMetaPathWayPoint,FDefaultAllocator> &'

looks like he want to use only this constructor

 FMetaNavMeshPath(const TArray<FMetaPathWayPoint>& InWaypoints, const ANavigationData& NavData);

instead of

 FMetaNavMeshPath(const TArray& InWaypoints, const AController& Owner);

any idea?

Snippet of my testing code here:

 TArray<FVector> Locations;
 Locations.Add(FVector(250.f, 250.f, 0.f));
 Locations.Add(FVector(450.f, -250.f, 0.f));
 Locations.Add(FVector(650.f, 250.f, 0.f));
     
 AController* Controller = Cast<AController>(GetOwner());
 FMetaNavMeshPath *MetaNavMeshPath = new FMetaNavMeshPath(Locations, Controller);
 
 TSharedPtr<FMetaNavMeshPath, ESPMode::ThreadSafe> MetaPathPtr(MetaNavMeshPath);
 
 InPath = FNavPathSharedPtr(MetaPathPtr);








avatar image kamrann Jul 18 '18 at 03:32 PM

You need to dereference your pointer. It's not common in the engine, but some of the AI code has (sensibly) started to use references instead of pointers to objects in function parameters. FMetaNavMeshPath(Locations, *Controller);

avatar image ZioYuri78 Jul 18 '18 at 04:49 PM

Holy cow! That was simple! Thanks a lot :)

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

More Info and a Wiki

To expand on Mieszko's (Hi Miezsko!) answer,

I have a wiki with code samples on the subject of custom UE4 AI pathing here!

Wiki on Custom AI Pathing in UE4 https://wiki.unrealengine.com/AI_Navigation_in_C%2B%2B,_Customize_Path_Following_Every_Tick

Rama

more ▼

answered Apr 21 '15 at 08:50 AM

avatar image

Rama
10.6k 446 345 1088

avatar image jechli Jun 03 '15 at 08:37 PM

Hey guys, thanks for the reply! I've put this task off for a bit but now I'm back at it.

I've attempted to make some changes in SetMoveSegment() and FollowPathSegment(), and I've got my path following component initialized in my custom ai controller (I think):

 ASKIMEGController::ASKIMEGController(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer.SetDefaultSubobjectClass<USKIMEGPathFollowingComponent>(TEXT("MEGPathFollowingComponent")))

I ran the game in the editor and everything worked as if I never changed anything. Then I ran it in debugging editor mode, and placed breakpoints in those two overridden functions. After running my AI in the game for a few minutes the breakpoints were never triggered, meaning my path following component isn't being run in the first place. Am I initializing it incorrectly?

avatar image kamrann Jun 04 '15 at 07:42 AM

The name passed into SetDefaultSubobjectClass should match up with the name that the parent class (in this case AAIController) uses when creating the component. It's a bid fiddly, as far as I know currently you just have to check the engine source code to find out. So anyway, you need to change it to:

 ObjectInitializer.SetDefaultSubobjectClass<USKIMEGPathFollowingComponent>(TEXT("PathFollowingComponent"))

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question