Ok, I created an example from the third person template. I created an actor called “TargetPointActor” and placed it in the map behind some obstacles.
(EDIT: I almost forgot, you need to add a Nav Mesh Bounds Volume to your level and increase the size to encompass anywhere you want pathing to take place)
I then made an event in the character blueprint when you press “Enter”:
First it gets all actors of class “TargetPointActor” and grabs the first one (index 0). There will only be one so this will get the one placed in the level.
Then, it executes the “Find Path to Location Synchronously” from the character’s location to the TargetPointActor’s location. Dragging off the return value, you can get the “Path Points” that make up this path. Saving it to a variable makes it easy to handle later.
Then it runs a loop. It needs to loop until the index is beyond the length of the Path Points. First, it sets the iterator (I called it an “index” here) to 0 to ensure it starts at the beginning. Then it executes the main body of the loop (handled here by having an execution loop back around to a branch until the branch’s condition is not met).
The first part of the loop obtains the location of the path point at the current index and subtracts it from the player’s location. Then, “Vector Length” is used to get the distance between the two points. If the character is within 100 units (close enough) of the point, increment the index and restart the loop, so it starts pointing us towards the next point.
If the character is not within 100 units of the next point, the character needs to be moved towards the next point. By subtracting the location of the next point form the character’s current point (and yes, this is the same difference used in the previous part), we can feed that into the “World Direction” of a “Add Movement Input” node and it will move the character towards the second point.
A “Delay” is needed at the end here because without it, UE4 thinks there’s an infinite loop. Make sure the delay isn’t too large or you’ll see the character stuttering while it moves.
Anyway, that should do it. This could be easily modified to randomly get a point on the map and move to it. You can’t put this inside a function, unfortunately, because you can’t use “Delay” there. hope this helps!