Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Check If AI Path Is Blocked on Grid Placement System


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:

alt text

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 @mighty, 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:

alt text

Product Version: UE 4.20
more ▼

asked Oct 19 '18 at 08:07 PM in Blueprint Scripting

avatar image

37 3 4 12

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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.

more ▼

answered Oct 19 '18 at 09:32 PM

avatar image

3.8k 18 23 20

avatar image mightyenigma Oct 19 '18 at 09:33 PM

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.

avatar image Austinlele Oct 19 '18 at 09:36 PM

I will give it a shot and report back!

avatar image mightyenigma Oct 19 '18 at 09:49 PM

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.

avatar image Austinlele Oct 19 '18 at 09:53 PM

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

avatar image mightyenigma Oct 19 '18 at 10:01 PM

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.

avatar image mightyenigma Oct 19 '18 at 10:03 PM

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)

avatar image Austinlele Oct 19 '18 at 10:35 PM

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)

avatar image mightyenigma Oct 20 '18 at 12:02 AM

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.

avatar image Austinlele Oct 20 '18 at 03:56 PM

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: https://blueprintue.com/blueprint/xdq2dsd9/. 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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question