# Forcing Ai to go back to nav mesh when leaves it

**URL:** <https://forums.unrealengine.com/t/forcing-ai-to-go-back-to-nav-mesh-when-leaves-it/608750>\
**Category:** AI\
**Tags:** ai-navigation, unreal-engine, UE4, Blueprint, question\
**Created:** [July 19, 2022, 7:20pm UTC](https://forums.unrealengine.com/t/forcing-ai-to-go-back-to-nav-mesh-when-leaves-it/608750 "2022-07-19T19:20:06Z")\
**Posts on this page:** 20\
**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, 7:20pm UTC](https://forums.unrealengine.com/t/forcing-ai-to-go-back-to-nav-mesh-when-leaves-it/608750/1 "2022-07-19T19:20:06Z")

</div>

This is kinda hard to explain why i need it but is there any way to make Ai character move back to nearest location of the navigation mesh? for exemple imagine there is a planar non nav mesh area (restricted with nav modifiers) in the map and I throw the ai character to that area and it stops moving because it doesnt have navigation area, is there any way to force the ai to move to a near navigable area so it can keep with is life?

---

<div class="post-metadata">

**Author:** ![jwatte](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jwatte/32/744941_2.png) [@jwatte](https://forums.unrealengine.com/u/jwatte)\
**Post date:** [July 19, 2022, 7:38pm UTC](https://forums.unrealengine.com/t/forcing-ai-to-go-back-to-nav-mesh-when-leaves-it/608750/2 "2022-07-19T19:38:55Z")

</div>

The problem is that the nav mesh is by definition the area where the AI knows how to navigate the character, and when outside the mesh, the AI doesn’t know how to navigate.  
You will have to figure out what behavior you want to move the character back to the point.  
You can use a function to get the nearest point on a navmesh to some other point, but there’s no guarantee that this point isn’t blocked by a wall or something similar.  
So – you could get the nearest point on the navmesh, and then lerp the position of the thrown character to that point over some amount of time, and that would put the character back on the navmesh, but it won’t interact well with arbitrary geometry.

---

<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, 7:44pm UTC](https://forums.unrealengine.com/t/forcing-ai-to-go-back-to-nav-mesh-when-leaves-it/608750/3 "2022-07-19T19:44:00Z")

</div>

Hi there, there are special actors called navlinks that serve to connect two navmesh volumes. These actors are also used if you want AI to jump between platforms. But, as stated before, your code should search for a reachable/navigable location before spawning the AI actor in the first place. There are nodes that handle such queries and return a feasible location.

---

<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, 9:15pm UTC](https://forums.unrealengine.com/t/forcing-ai-to-go-back-to-nav-mesh-when-leaves-it/608750/4 "2022-07-19T21:15:36Z")

</div>

what nodes can i use to get that nearest location point on nav mesh?

---

<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, 9:20pm UTC](https://forums.unrealengine.com/t/forcing-ai-to-go-back-to-nav-mesh-when-leaves-it/608750/5 "2022-07-19T21:20:19Z")

</div>

Hi, I didnt want it to spawn was more like move it from a “forbidden” zone, for example, my floor is always plane but are some areas that have a nav modifier so the npc doesnt go there but sometimes gets thrown in there and cant leave, i just really need it to walk to the nearest location on nav mesh, do you know any nodes that gives me that or something similar?

---

<div class="post-metadata">

**Author:** ![jwatte](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jwatte/32/744941_2.png) [@jwatte](https://forums.unrealengine.com/u/jwatte)\
**Post date:** [July 19, 2022, 10:40pm UTC](https://forums.unrealengine.com/t/forcing-ai-to-go-back-to-nav-mesh-when-leaves-it/608750/6 "2022-07-19T22:40:13Z")

</div>

You can’t use the AI movement nodes because they need the navigation mesh.  
You’ll want to make a node that manually turns the character towards the target point, and manually emits the “Add Movement Input” call to the character each tick.  
This is really no different from the input handling code in the player pawn – “if I want to move forward, add movement input with X=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 20, 2022, 12:00am UTC](https://forums.unrealengine.com/t/forcing-ai-to-go-back-to-nav-mesh-when-leaves-it/608750/7 "2022-07-20T00:00:38Z")

</div>

i did that manage to get back to the nav mesh but it seems that the " add movement input with X=1” keeps going for ever making the character move in a straight line bumping to walls and not rotating like its should, how to i fix this? I tried to put x=0 after a delay of 2 seconds and nothing

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/a/3/5a32928b2059d316d003e3a03ed2ce44ad722d16.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, 1:55am UTC](https://forums.unrealengine.com/t/forcing-ai-to-go-back-to-nav-mesh-when-leaves-it/608750/8 "2022-07-20T01:55:17Z")

</div>

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:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/1/f/11fb767070e0bdad6844ac62e66533a4d05be02e.jpeg)

this is the nav modifier inside the door blue print:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/9/b/19b4619ae438c367f18b55a1279d87fb22446d67.jpeg)

i cant change the size or anything to make that area smaller, how can i fix this?

---

<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 20, 2022, 1:14pm UTC](https://forums.unrealengine.com/t/forcing-ai-to-go-back-to-nav-mesh-when-leaves-it/608750/9 "2022-07-20T13:14:51Z")

</div>

If you can make a code that detects whenever the AI reaches a forbidden area, then you have a solution. Either throughout overlaps or phyical materials in the floor. I am not sure if is possible to detect the presence of a navmesh modifier, unless you add box collisions to that. So everytime the AI passes through it, you can trigger “on begin overlapping” events.

---

<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, 1:22pm UTC](https://forums.unrealengine.com/t/forcing-ai-to-go-back-to-nav-mesh-when-leaves-it/608750/10 "2022-07-20T13:22:52Z")

</div>

That area in red wasnt suppose to be that big and it exists because the area class of nav modifier on the door bp is set to “obstacle” do you know how to make it smaller?

---

<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 20, 2022, 1:28pm UTC](https://forums.unrealengine.com/t/forcing-ai-to-go-back-to-nav-mesh-when-leaves-it/608750/11 "2022-07-20T13:28:54Z")

</div>

I am quite sure you may be able to reduce the scale of the navmesh modifier box. Select the modifier and take a look at details panel. Look for scale xyz or box dimensions. I am out of town without my computer, I am unable to review this information.

---

<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, 1:34pm UTC](https://forums.unrealengine.com/t/forcing-ai-to-go-back-to-nav-mesh-when-leaves-it/608750/12 "2022-07-20T13:34:46Z")

</div>

I cant this is all options i have:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/9/3/f93a3f39d1ad851e463ae38bc4d8628ffd143e15.jpeg)

---

<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 20, 2022, 1:41pm UTC](https://forums.unrealengine.com/t/forcing-ai-to-go-back-to-nav-mesh-when-leaves-it/608750/13 "2022-07-20T13:41:53Z")

</div>

It seems there is no option to resize it, because it is an actor component, not a primitive component.

---

<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 20, 2022, 1:49pm UTC](https://forums.unrealengine.com/t/forcing-ai-to-go-back-to-nav-mesh-when-leaves-it/608750/14 "2022-07-20T13:49:18Z")

</div>

I would try differently. Remove the navmodifier and add a cube static mesh. Resize it to your needs and add a code that change its collision settings as follows:  
Door: locked - set cube collision as “block pawn” and “can ever affect navigation” to true.  
Door: unlocked - set cube collision to ignore all and set “can ever affect navigation” to false.

---

<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, 1:49pm UTC](https://forums.unrealengine.com/t/forcing-ai-to-go-back-to-nav-mesh-when-leaves-it/608750/15 "2022-07-20T13:49:53Z")

</div>

So how do I add a primitive component to the bluprint? also is there any way to edit area classes?

---

<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 20, 2022, 2:04pm UTC](https://forums.unrealengine.com/t/forcing-ai-to-go-back-to-nav-mesh-when-leaves-it/608750/16 "2022-07-20T14:04:29Z")

</div>

A static mesh is a primitive. Click on the green button “+ add component”. See my previous post.

---

<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, 5:20pm UTC](https://forums.unrealengine.com/t/forcing-ai-to-go-back-to-nav-mesh-when-leaves-it/608750/17 "2022-07-20T17:20:16Z")

</div>

The Problem is that i cant acess the “can ever affect navigation” via nodes in bp, i found a solution that was: creating a separate blue blueprint with only a nav modifier (if there is only the nav modifier i can select the affected area in the Failsafe Extente parameter, dont know why tho) and set this nodes inside of this blueprint:

[https://forums.unrealengine.com/t/how-to-make-ai-look-for-other-way-when-the-path-is-blocked/608096/16~](https://forums.unrealengine.com/t/how-to-make-ai-look-for-other-way-when-the-path-is-blocked/608096/16~)

If the area class of the nav modifier is set to “obstacle” the AI seems to avoid it while it can walk on it.

Then i placed thos nav mod BP in the places i want the AI to avoid if it gets sent there

---

<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 20, 2022, 5:45pm UTC](https://forums.unrealengine.com/t/forcing-ai-to-go-back-to-nav-mesh-when-leaves-it/608750/18 "2022-07-20T17:45:09Z")

</div>

Sounds good.

---

<div class="post-metadata">

**Author:** ![eblade](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@eblade](https://forums.unrealengine.com/u/eblade)\
**Post date:** [July 21, 2022, 5:33pm UTC](https://forums.unrealengine.com/t/forcing-ai-to-go-back-to-nav-mesh-when-leaves-it/608750/19 "2022-07-21T17:33:39Z")

</div>

Use Project Point To Navigation, or you can probably use an EQS query (i don’t have much experience with those yet). [ProjectPointToNavigation | Unreal Engine Documentation](https://docs.unrealengine.com/4.26/en-US/BlueprintAPI/AI/Navigation/ProjectPointToNavigation/)

If your characters are NavMeshWalking, they should switch to Walking automatically once they are off the mesh.

Once you find a point, do a MoveToLocation() with pathfinding turned off, and it should get you there. If it does not, you could either lerp to it, or just teleport to it.

Then if you’re using NavMeshwalking, make sure you switch that back on once they are back on the mesh.

---

<div class="post-metadata">

**Author:** ![TorQueMoD](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/torquemod/32/710746_2.png) [@TorQueMoD](https://forums.unrealengine.com/u/TorQueMoD)\
**Post date:** [February 26, 2023, 12:25am UTC](https://forums.unrealengine.com/t/forcing-ai-to-go-back-to-nav-mesh-when-leaves-it/608750/20 "2023-02-26T00:25:01Z")

</div>

I realize it’s been a while, but I only had reason to figure this out myself last night. Regardless, I created a tutorial with my solution:

[![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/c/3/5c32b8349a0a55b8cd56337f029ea11eca963aea.jpeg "UE4/5 - Find Nearest/Closest Point On Navmesh") ](https://www.youtube.com/watch?v=L1zEGNTioO8)

Hope it helps someone!

[Next page](https://forums.unrealengine.com/t/forcing-ai-to-go-back-to-nav-mesh-when-leaves-it/608750.md?page=2)
