# How to make AI look for other way when the path is blocked?

**URL:** <https://forums.unrealengine.com/t/how-to-make-ai-look-for-other-way-when-the-path-is-blocked/608096>\
**Category:** AI\
**Tags:** unreal-engine, UE4, Blueprint, question\
**Created:** [July 19, 2022, 2:27am UTC](https://forums.unrealengine.com/t/how-to-make-ai-look-for-other-way-when-the-path-is-blocked/608096 "2022-07-19T02:27:06Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lamaral14](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Lamaral14](https://forums.unrealengine.com/u/Lamaral14)\
**Post date:** [July 19, 2022, 2:27am UTC](https://forums.unrealengine.com/t/how-to-make-ai-look-for-other-way-when-the-path-is-blocked/608096/1 "2022-07-19T02:27:06Z")

</div>

I have this npc that follows sound lures when they are activated, the way it work is: when the player activates the lure the ai move to that lure location through the shortest path via nav mesh, but sometimes there is obstacles in the way that dont influence the nav mesh and the ai keeps bumping those obstacles instead of finding a clean way:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/7/1/871e61b2bdd16e6fe5422365e606331e1f8c9acd.jpeg)  
As you can see here the door doesnt mess with the nav mesh, and some doors are locked and can be unlocked and sometimes the ai keeps trying to pass trough those doors instead of going other way, how do I fix that?

---

<div class="post-metadata">

**Author:** ![gh0stfase1](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/gh0stfase1/32/1194639_2.png) [@gh0stfase1](https://forums.unrealengine.com/u/gh0stfase1)\
**Post date:** [July 19, 2022, 2:05pm UTC](https://forums.unrealengine.com/t/how-to-make-ai-look-for-other-way-when-the-path-is-blocked/608096/2 "2022-07-19T14:05:58Z")

</div>

This is a fairly complex topic and it’s largely dependent on your desired result. For instance, if your NPCs can open doors then you’ll likely need some collision box on the door that can detect overlaps with an NPC and then direct the NPC to run an open door animation. If they can’t open the door then you’re going to need to block that path from the nav mesh. Off the top of my head I’m unsure how to do that.

---

<div class="post-metadata">

**Author:** ![dowhilefor](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dowhilefor/32/552685_2.png) [@dowhilefor](https://forums.unrealengine.com/u/dowhilefor)\
**Post date:** [July 19, 2022, 2:08pm UTC](https://forums.unrealengine.com/t/how-to-make-ai-look-for-other-way-when-the-path-is-blocked/608096/3 "2022-07-19T14:08:54Z")

</div>

With a dynamic navmesh that should be fairly trivial. When the door is closed, set bCanAffectNavigationGeneration to true. That way the navmesh is rebuild taking the doors collision as blocking into account, and your agent won’t try to walk that way. When the door is opening, set bCanAffectNavigationGeneration to false, depending on how your animation works, wait till it is open and not moving again and set it to true again.

---

<div class="post-metadata">

**Author:** ![kribbeck](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@kribbeck](https://forums.unrealengine.com/u/kribbeck)\
**Post date:** [July 19, 2022, 2:32pm UTC](https://forums.unrealengine.com/t/how-to-make-ai-look-for-other-way-when-the-path-is-blocked/608096/4 "2022-07-19T14:32:59Z")

</div>

Hey @Lamaral14, I think what you want is a NavMesh Modifier. You want your doors to modify the navmesh, blocking it when closed and enabling it when open.

---

<div class="post-metadata">

**Author:** ![L.F.A](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/l.f.a/32/1194525_2.png) [@L.F.A](https://forums.unrealengine.com/u/L.F.A)\
**Post date:** [July 19, 2022, 2:36pm UTC](https://forums.unrealengine.com/t/how-to-make-ai-look-for-other-way-when-the-path-is-blocked/608096/5 "2022-07-19T14:36:07Z")

</div>

There is a node called “Does the path exists?”, which can be used  
as a condition to the “move to” node.

More refined workflows would also include:  
Add an actor tag to the enemy and whenever the AI appoaches a closed door, the door overlap event checks “actor has a tag?” and the door opens.

---

<div class="post-metadata">

**Author:** ![Lamaral14](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Lamaral14](https://forums.unrealengine.com/u/Lamaral14)\
**Post date:** [July 19, 2022, 5:23pm UTC](https://forums.unrealengine.com/t/how-to-make-ai-look-for-other-way-when-the-path-is-blocked/608096/7 "2022-07-19T17:23:36Z")

</div>

I have done this but i see no changes:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/9/3/293c7beff3a7453d00db4fa4197b8d5241222d97.png)

But when i do check/uncheck on the “door” mesh it does:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/9/c/99c2936731d44a68cdae6c05863cdd9da2344c6f.png)  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/2/c/02c90be355d4847b2a3451f1175b2fabab9cafdc.jpeg)

The thig is that the CanAffectNavigationGeneration doesnt seem to work with meshes only pawns, i already changed my bp to a pawn and did that thing in the event tick above but no changes, the mesh only changes when i check the box of the door mesh and cant program it because i cant acess it

---

<div class="post-metadata">

**Author:** ![Lamaral14](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Lamaral14](https://forums.unrealengine.com/u/Lamaral14)\
**Post date:** [July 19, 2022, 5:38pm UTC](https://forums.unrealengine.com/t/how-to-make-ai-look-for-other-way-when-the-path-is-blocked/608096/8 "2022-07-19T17:38:25Z")

</div>

i forgot to mention that hte move to is the one of the behaviour tree not the node of blueprint

---

<div class="post-metadata">

**Author:** ![L.F.A](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/l.f.a/32/1194525_2.png) [@L.F.A](https://forums.unrealengine.com/u/L.F.A)\
**Post date:** [July 19, 2022, 6:00pm UTC](https://forums.unrealengine.com/t/how-to-make-ai-look-for-other-way-when-the-path-is-blocked/608096/9 "2022-07-19T18:00:43Z")

</div>

In this case, try to add a “does path exists?” check in that move to node. Hope that helps.

---

<div class="post-metadata">

**Author:** ![dowhilefor](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dowhilefor/32/552685_2.png) [@dowhilefor](https://forums.unrealengine.com/u/dowhilefor)\
**Post date:** [July 19, 2022, 6:11pm UTC](https://forums.unrealengine.com/t/how-to-make-ai-look-for-other-way-when-the-path-is-blocked/608096/10 "2022-07-19T18:11:06Z")

</div>

Is your nav mesh set to dynamic? I’m not sure what you mean with “no changes” because your screenshot clearly shows that the door is now blocking the navmesh.

> The thig is that the CanAffectNavigationGeneration doesnt seem to work with meshes only pawns

No, it works with all actors that have a collision.

---

<div class="post-metadata">

**Author:** ![Lamaral14](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Lamaral14](https://forums.unrealengine.com/u/Lamaral14)\
**Post date:** [July 19, 2022, 6:18pm UTC](https://forums.unrealengine.com/t/how-to-make-ai-look-for-other-way-when-the-path-is-blocked/608096/11 "2022-07-19T18:18:52Z")

</div>

Well i did that but the result is the same since the nav mesh still exists there, the ai just keeps bumping the door

---

<div class="post-metadata">

**Author:** ![Lamaral14](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Lamaral14](https://forums.unrealengine.com/u/Lamaral14)\
**Post date:** [July 19, 2022, 6:29pm UTC](https://forums.unrealengine.com/t/how-to-make-ai-look-for-other-way-when-the-path-is-blocked/608096/12 "2022-07-19T18:29:00Z")

</div>

It is set to dynamic, please let me be more clear:

1st- the changes only happen when i checked the box " Can ever affect navigation" on the “door” mesh, the problem is that i cant program that because i cant acess it in the blueprint

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/4/a/04a10cf5db097715a09de4d0a267f0b29c4d69cc.png)  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/6/9/4697e1f08c5eddab2d60b76bf6cc6084f08158f0.jpeg)

2nd- I used the “CanAffectNavigationGeneration” node requires a pawn as target, my door bp is now set to be a pawn, but its not changing the nav mesh:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/1/9/a199b6e9e88001ed40e5b0fec38ecd0b4208d52f.png)  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/2/2/d22aa50bcd54e2027bcaa8c9c357b2cf88ecdbc3.jpeg)  
In this case i uncheck the box of the “door” mesh mentioned before (the one i cant program), and you can see that the variable " is door locked" is set to true and its not changing the mesh

---

<div class="post-metadata">

**Author:** ![dowhilefor](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dowhilefor/32/552685_2.png) [@dowhilefor](https://forums.unrealengine.com/u/dowhilefor)\
**Post date:** [July 19, 2022, 6:32pm UTC](https://forums.unrealengine.com/t/how-to-make-ai-look-for-other-way-when-the-path-is-blocked/608096/13 "2022-07-19T18:32:41Z")

</div>

I understand now, the property is not exposed to blueprint but in c++ … [kribbeck](https://forums.unrealengine.com/u/kribbeck) idea with the navmesh modifier is then the next best thing. That should be able to toggle in blueprint.

---

<div class="post-metadata">

**Author:** ![Lamaral14](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Lamaral14](https://forums.unrealengine.com/u/Lamaral14)\
**Post date:** [July 19, 2022, 6:36pm UTC](https://forums.unrealengine.com/t/how-to-make-ai-look-for-other-way-when-the-path-is-blocked/608096/14 "2022-07-19T18:36:55Z")

</div>

Im gonna try that, but shouldnt the “CanAffectNavigationGeneration” node be working since the door is a pawn? why does not work can you explain me please?

---

<div class="post-metadata">

**Author:** ![dowhilefor](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dowhilefor/32/552685_2.png) [@dowhilefor](https://forums.unrealengine.com/u/dowhilefor)\
**Post date:** [July 19, 2022, 6:43pm UTC](https://forums.unrealengine.com/t/how-to-make-ai-look-for-other-way-when-the-path-is-blocked/608096/15 "2022-07-19T18:43:44Z")

</div>

I checked the c++ code and it basically boils down to calling

`CollisionComponent->SetCanEverAffectNavigation(bCanAffectNavigationGeneration);`

So at this time, i’m not sure. Maybe a restart could help. But setting it to dynamic, should allow you to do what i show in the video. If that doesn’t work, then your nav mesh generation has problems. That can be solved by deleting RecastNavMesh-Default, restarting and rebuilding the navigation

[![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/b/2/6b230795055805de301bd8445d7c97548b86f14a.jpeg "Unreal dynamic runtime nav mesh") ](https://www.youtube.com/watch?v=23mbB5F-T5w)

---

<div class="post-metadata">

**Author:** ![Lamaral14](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Lamaral14](https://forums.unrealengine.com/u/Lamaral14)\
**Post date:** [July 19, 2022, 6:49pm UTC](https://forums.unrealengine.com/t/how-to-make-ai-look-for-other-way-when-the-path-is-blocked/608096/16 "2022-07-19T18:49:24Z")

</div>

i have it set to dynamic like in the video and restarted the software but still doesnt work, but i did that @kribbeck sugestion and it worked:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/a/6/9a6ec4ca9a6999091c18ce68972a08ad7e10c317.png)

---

<div class="post-metadata">

**Author:** ![Lamaral14](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Lamaral14](https://forums.unrealengine.com/u/Lamaral14)\
**Post date:** [July 20, 2022, 2:00am UTC](https://forums.unrealengine.com/t/how-to-make-ai-look-for-other-way-when-the-path-is-blocked/608096/18 "2022-07-20T02:00:19Z")

</div>

I used a nav modifier but the area that is influencing is too big and its bugging my game out:

> [@Forcing Ai to go back to nav mesh when leaves it](https://forums.unrealengine.com/t/forcing-ai-to-go-back-to-nav-mesh-when-leaves-it/608750/8):
>
> I figure ity it was a nav modifier inside a blue print that was causing this glitch, the said nav modifier is turning the nav mesh red in a huge area: this is the nav modifier inside the door blue print: i cant change the size or anything to make that area smaller, how can i fix this?

do you know how to fix this?
