How to make AI walk around walls if it's possible, but destroy them if not?

I am making a Clash of Clans like game and have ran into this issue regarding walls. My AI works as follows:

  • Upon spawning, it will get the closest building of a certain type (Enum Class) and pick that as its target if it has available attacking spaces around it (represented by Collision Spheres)
  • AI will proceed to move to that location and attack the Building

I am using a Navigation Mesh and the AI Move To node in a Behavior Tree for this. Now the issue I am running into is when creating walls that should prevent the AI from going through them. I’m struggling to find a way to solve edge cases like this for example:

In this example, AI should not attack any of the first row walls as it isn’t necessary but should attack the second row.

My logic was to do something like this:

  • AI moves to its desired location
  • If the AI’s custom Collison Box Component overlaps with any wall → pick that wall as your target
  • Wall dies → find closest building that you would like to attack

However, this runs into multiple problems like in the picture above, if an AI touches the first row it will attack it instantly. I am attacking with a lot of units and using RVO avoidance so using blocking volumes on the Nav Mesh is not an option as this would not cover all edge cases and would go terribly wrong somewhere (different unit counts, layouts etc…).

I’m doing the same thing, DId you find any solution?

I have a way that works for me so I’ll share it.

I put a nav modifier on my walls so that the AI will walk around it. If the wall is to long and therefore to expensive to walk around they will try to walk through the walls. I then have a line trace that shoots 100 units in front of the AI so that when they collide with the wall the line trace hits the wall, detects there is a structure in front of it, then I trigger the attacking.

That’s the shortest answer I can give without writing 2 pages of how its set up.
hope it helps.