Check If AI Path Is Blocked on Grid Placement System

Hello!

Looking for assistance on scripting a tower grid placement system for a defense type game… What functionality I am struggling to create is a blocking system that knows an AI character could make it to the destination point. I do not want to allow the player to place a unit on the grid that would block the AI from making it to the end. I am using a standard navmesh for the AI, no EQS. This is a Mobile project as well.

Like so:

How can I create a placement script that knows a path would be blocked? (the yellow area should be “off limits” but currently it’s possible to place a unit). I need this to work at any point in the grid.

Any advice, tips, tricks, help is appreciated!

EDIT: Using the advice of @anonymous_user_fd378872, I use the path tester pawn to spawn in, check the path, then return if the path is partial or not. From that I can branch whether placement of a unit is valid or not. But I have an issue:

I will give it a shot and report back!

If you’re using NavMesh, you could use an EQS Pawn that has the same AI Controller to query the navigability, but first you block him with an Actor class that only blocks EQS Pawns and not the real enemies, as you hover over the spot. You can have your cursor be that Actor class maybe, or have that Actor class always teleport to where the cursor is sitting.

Then before placing the obstacle, you can have it check with the EQS Pawn that starts on the enemies’ end of the playfield, whether it is blocked from getting to the player’s base. If it is, then it does not allow the placement of the obstacle.

I don’t know if this will work because I have only watched a tutorial about EQS but never tried using it myself.
Seems like it should work though.
Let me know how it goes.

ACtually come to think of it, it doesn’t even need to be an EQS pawn. It could just be the same Pawn class as the actual enemies but maybe force it to stay inside the enemy base and be invisible.

I think I read there is a node that tests if the location can be reached (using the navmesh) so that’s how to test if the pathway would be blocked. Make sure the pawn you use for the query is blockable by the placed obstacles, by the cursor, but not by other pawns. You can change collision channel settings on individual pawns at runtime (there’s a node for that) so you could just use a standard enemy character pawn to make sure he fits through the gap, can jump the same way, etc.

One thing that trips me up at the moment is that the “blocking unit” hasn’t been placed yet, so of course the path will be open when i do this ai path check prior to placing the unit. How can I go about faking the unit placement, doing the path check, then determining validity? without much performance loss mind you, this is mobile ha. Thanks

That actually makes sense haha, this doesn’t sound super performant but it does sound like it should work. I’ll give it a go for real in a couple hours time. Do you think there is a way for the grid to look and see if it has a valid path around it relative to the other grids? (not sure that makes any sense)

Well not sure how it would perform on mobile but like I said, the cursor can have a collision channel that only matches with your query pawn’s collision type, and not with any of the other pawns of that class (by setting the query pawn’s collision type right after spawning him).

He doesn’t have to actually travel there, he just has to ask the navmesh if he can reach the player’s base from where he’s at and then tell the player “NOPE CAN’T PLACE THAT”. if the answer is no.

You can have the cursor and the query pawn communicate all of this when the player clicks to place the building, and then only place it after it gets an answer of YES I CAN STILL GET TO THE PLAYERS BASE

Does that make sense? It won’t block the other pawns because they’ve all kept their normal collision types that don’t care about cursors or the collision volumes attached to them that are the exact same size as the building you’re going to place.

So basically my idea is that the cursor always has a blocking volume attached to it that’s the size of the unit selected for placement, but it’s collision type is ignored by everyone but the query pawn(s)

Nit sure how you mean by realtive to other grids but an alternative to the navmesh is the A-star algorithm byt that requires you to have the grid and its current obstacles stored in some kind of indexable data structure and update it whenever something changes.
They use it in the live training video about turn based project template (and in the project itself)
Not sure if ut us more or less performant than navmesh- probably depends on grid density.

I’m having some bad luck with this… Not sure where I’ve gone wrong but I bet it’s something small. Here is my path tester macro: MyPlayerController-PathTester posted by anonymous | blueprintUE | PasteBin For Unreal Engine 4. The grid “Tile” has a collision box set to ignore the path tester normally, but then i set it to BLOCK the path tester in that macro first and foremost. When I place the last “blocking” unit, I got Partial = false, and a valid path. The next unit I place in ANY grid tile then produces the expected result of Partial = true. I’m confused.