Detecting pawns: Sphere collision overlap vs Get all actors of class

Hi, I’m trying to have my AI units (Type A) detect other types of AI units (Type B) within a certain radius. At any time, this check would contain anywhere up to a maximum of 20 units. The map is not open world, and the map size will probably be around 2-5 times the game space in top down template. Also the game is turn based, so I do not need real time checks either. Right now, I could try out a sphere component overlap from each pawn or use the get all actors from class and line trace them. Given the situation, I would like to know which of these methods will be better.

I think you’ve got the right ideal. The sphere component would give more dynamic results Even if your game is turned based, you may want your game to recognize another pawn nearby during its current move in case you have ambush mechanics or what not. If the ai being within the radius of another ai only matters between turns then you don’t really need the sphere component and could query nearby ai’s with get all actors from class and compare world locations. You don’t need a trace to do this, just compare their x,y,z and if any of said values are < then X they are within radius.

Thanks for the answer. As a matter of fact, I will most probably have ambush scenarios. But I was thinking that whenever a unit goes into an ambush mode, it changes a bool value and gets added to an array for reference. Any unit from the opposing team makes a move command and the bool is checked, the data retrieved from the array and does the action accordingly. So in a manner I was having the ambush check triggered only when a certain command like movement has been issued, instead of calling it real time. And that actually put me into a lot of confusion as to what I should be using.

It sounds like you may want to have some kind of grid layout to better keep track of positioning and movement. They have a turn based strategy game in the example projects that you could use as reference. The ambush thing is fine but you still need to determine the location when you check for ambushes to make sure it only ambushes nearby targets. With a grid you can pre determine every possible actions, movements, locations before the turn is played. I guess it depends on the complexity of what you want to do but from what I’ve gathered so far, using pre-determined world positions within a grid or hexagon layout would be better. And then it would be easy to implement features like certain terrain tiles cost more movement points and what not. But I’m still kinda just guessing at what you are attempting to do. Good luck!

I was trying Wasteland 2 the other day, kinda sounds like what you are trying to do!

Hi, I’ve been talking with that guy over the past few weeks. I will most probably switch to using a lot of his pathing/grid code. I’m working on something very similar to XCOM. I’m trying to achieve most of it’s combat gameplay only using blueprints. At the moment, I don’t have any underlying grids. Instead I’m generating a visual representation of grids at run time. It already takes into account movement points, fire points, end turn logic. Since I didn’t use any AI code yet, I did not have any issue with not storing the entire grid details.

But as you mentioned, it’s probably going to become more efficient to use grids, than my current system as the game gets more complex. I can probably choose not to render the grids to make it efficient. Anyways just so that you get an idea of what I’m doing, feel free to check out this video:

Unreal Engine 4 Dev Video #20: Real Time Grid Generation