Download

Error in order of the target points to be followed. How to set the order of elements in an array?

I have a project where it has 1 NPC and 3 target points:


In the project I set the NPC to go to target point 1, then to 2, then to 3.

Expected path:


Path that is occurring:


This problem did not happen out of nowhere, but first I will explain the creation of the target points.

I created the first target point, added the components it needed, and then replicated it. Selecting the first target point and pressing CONTROL + W. I positioned the second target point, and then, again selecting the first target point, I again replicated it.

The order of the path was as expected. I modified some code (none of the codes I modified related to the NPC or target points). After that I created a new target point (replicating it from the first target point) and then my problem started.

The NPC was initially going to target point 3, to the 4, 1 and then 2.

Even excluding target point 4, the order did not return to the expected (1, 2 and 3).

I inserted a print after the loop that causes the NPC to move toward the target points, so I could figure out the order of the target points, and it is making sense with the order of the path that is taking place.

Blueprint + Print:


3 to 1 to 2.

I created 2 more target points, and see how the order changes without any sense:

320.jpg

4 to 5 to 1 to 2 to 3.

I added another 1 target point to see if it meets a pattern:

321.jpg

No sense at all.

I’d like to know how to set the order of target points in the array.

Sorry for bad English, I’m not a language speaker.

I asked that same question on another site a few days ago (ai - Error in the order of the target points to be followed. How to set the order of elements in an array? - Game Development Stack Exchange), I researched order in an array and ways to set it, but I did not succeed.

You can Make Array and / or Set Array Element:

Capture.PNG

How do you gather the points atm,? If you’re using a *Get All *node, it’s not reliable for this.

Another solution is to use a spline, they’re always ordered. This seems related:

https://forums.unrealengine.com/deve…-patrol-points

I get this array through function Get All Actor of Class.

Blueprint:

And then I use that array in a loop. With that I make a path/circuit.

I looked at the link you sent, with some changes I can make the order I want.