0
\$\begingroup\$

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

enter image description here

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

Expected path:

enter image description here

Path that is occurring:

enter image description here

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:

enter image description here

3 to 1 to 2.

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

enter image description here

4 to 5 to 1 to 2 to 3.

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

enter image description here

No sense at all.

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


EDIT 1 (Root of the problem)

From what I researched, I came to the conclusion that the problem is due to the function Get All Actors Of Class (that I use to make the NPC follow the target point):

enter image description here

It was also researching that I discovered that I can search for a specific actor using tags.

Link where I made the discovery:

https://docs.unrealengine.com/en-us/Gameplay/HowTo/FindingActors/Blueprints

But this feature does not serve me, because I do not want to establish an exact number of target points, I would like the order of the path to be given by the name of the target points or at least by the creation order.


EDIT 2 (today opening the project again, the order is correct)

Correct order:

enter image description here

I suspected that if I added new target points, the problem would come back, but that was not what happened.

Again the order is correct:

enter image description here

Even so, I'd like you to tell me if there is any way to know all the elements of an array, and thus be able to treat, set, and order them. For this problem may occur again at some crucial moment.

\$\endgroup\$
1

1 Answer 1

0
\$\begingroup\$

Create an array of type actor.

Name the target points the way you prefer (I would recommend TP + his number):

enter image description here

Use the Get All Actor of Class to receive all the target points and then add to the vector you created:

enter image description here

From the vector you created, you use a loop. With an integer variable with the initial value of 1 (in my case) you use an append, with the name you put in your target points without the number. The number will be defined by this integer variable.

Below the loop that defines the target to be followed:

enter image description here

When the NPC collides with a target point, just increase the value of the integer variable and restart the loop that defines the target to be followed:

enter image description here

\$\endgroup\$
1
  • \$\begingroup\$ You only need one loop, not 2. \$\endgroup\$ Commented Jun 20, 2019 at 0:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .