Is there a distance limit to "Get all actors of class"?

So I’m building an opponent AI to handle unit movement in an RTS. And to do this I have placed “tactical points” around the map to mark good spots for the AI to place its units.

But while testing it I noticed that the system would only work up to a specific point. After that point any of the “tactical points”. And the script basically just check for the closest points that haven’t been claimed, claiming it and placing a move order.


Here you can clearly see the line where the “Tactical points” on the left aren’t being considered by the script while the ones on the right are.

So the question is, is there a limit to the “Get all actors of class”? Either array size limit or a distance of detection?

The function in blueprints GetAllActorsOfClass finds in the entire level with no distance limit.
BUT…
You can instead use SphereOverlapActors to get all actors within a given distance.

1 Like

Yes that’s what I’m considering switching to.

I’m more curious to why it suddenly just stoped detecting them, as all the previous point to the right should be claimed and not considered. But the NPCs are not pushing forward as they have done up until this point.
Sure some are currently stuck due to pathfinding issues, but there’s at least one squad that should be able to continue.

There can be many reasons for them to get stuck.

  • No path
  • Partly in the ground so collision locked.
  • Fell out of some update list so getting ignored
  • Out of movement points, or gas or energy
  • Waiting to fire or for someone else to take a turn
  • etc, etc, etc,

The only thing I can think of would be pathfinding. But it seem like one of the groups actually make it to their destiantion, but the script just doesn’t keep doing what it has been doing four times already.

Question is a bit broad, you need to simplify the situation and debug things one by one.
I would never use GetAllActorsOfClass , instead I would make manager classes which have their own tasks. To give an example, the units on your team could be managed by a Commanding class which holds all the units of its team under its command. That way you could improve performance already in a very simple way instead of using GetAllActorsOfClass (which might even get units of the other team.)
Another thing I wanted to point out is that a “tactical point” isn’t really a thing, “tactical” is a state based on a condition where “point” can be anywhere. imagine a strategy where a “tactical point” is a building except you put a few spiders in it and the attacking unit is a nuke. oops.

*Edit if the problem turns out to be with navigation, you can preview the pathfinding model in the editor. Pathfinding can also be configured to be dynamic.

That is exactly what I’ve done. I have a Commanding class (in my case “AI brain”) which take care of the moving the different units around. The units are grouped into squads with one leader unit.
“Tactical point” is just my name for an actor which gives a location and some information to the AI Brain (Currently just a location).

So the scenario is as follows.

  • The Ai brain detects all squads it has under it’s command and all tactical points.
  • The Ai give a command to the Leader of each squad to go to the closest tactical point. This tactical point becomes claimed until any unit of the squad reaches it.
  • When a unit of the claiming squad reaches the tactical point, the point get a 5 min coldown before it gets unclaimed. The AI brain gets an event to give a new command to the squad to move to the next unclaimed tactical point that is closest to the squad leader.
  • And so it loops at the moment.

And this works fine with 6 squads for the four first tactical points they move to. But all 6 squads fail as soon as they reach this row of tactical points. And as the screen shot show, there is a squad stadning in their claimed tactical point, but for some reason they don’t seem to try to claim the next set. None of them. And all previous tactical points are taged as claimed and won’t be considered as locations fora new move command.

Issues with get all actors of class is it’s expensive and there’s no particular order to the results. If you are going to use it, do it once and store the result return. Use this instead of calling get all actors of class again. Begin Play is a good place to run this.

An optional approach is to use Multi-sphere/box traces to get overlapping actors. But this will return assigned and claimed TP’s as well. You’ll need to filter the results.

The best option in my opinion is to have each TP report in to the Game mode (event dispatcher) and the game mode call an event on the AI Brain to add each “calling in” TP to an array. No loops needed, no get all actors needed, etc.


Next part is you’ll have to loop those results to find the closest (distance) TP that’s “unclaimed”. The best approach here is to first off only loop through unclaimed TP’s, so you’ll need two arrays. If you can only have 1 squad per TP, then you’ll need three arrays.

  • Tactical Points
  • Tactical Points Assigned
  • Tactical Points Claimed

Just a matter of getting the “distance” in a loop an return the closest to the current squad leader.

Next you take the result and move the TP to assigned array, then remove it from the TP array. Have the squad leader move to the location on the now assigned tp.

Roughly something like the following.

Overall… in AI Brain

In AI class…

Oh my that’s a lot of examples. Thank you so much!
This is sort of close to what I’m doing at the moment, but a lot more elegant.
The main difference seem to be that you move the TPs between different arrays were I use a bool variable in the TP instead. Looking at your example this would be just a one time claim and you can’t unclaim it, right? (Which would be to just move it back into the first TP array of course.)

But yes, that look like a good change for me to do as some extra debugging has made me realize that for some reason a TP can get claimed by multiple squads at the moment, and your example eliminates this possibility.

Yeah it’s all about moving TP’s between arrays. It was the simplest and most straight forward approach I could think of at that moment.

Personally I’d move all the TP arrays and shifting to the game mode. Have the AI Brain and TP’s call events in it.