# How to check if a point is reachable by pawn?

**URL:** <https://forums.unrealengine.com/t/how-to-check-if-a-point-is-reachable-by-pawn/367407>\
**Category:** AI\
**Tags:** pathfinding, Navigation, unreal-engine, question\
**Created:** [August 17, 2016, 11:39am UTC](https://forums.unrealengine.com/t/how-to-check-if-a-point-is-reachable-by-pawn/367407 "2016-08-17T11:39:31Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![AlexDiru](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AlexDiru](https://forums.unrealengine.com/u/AlexDiru)\
**Post date:** [August 17, 2016, 11:39am UTC](https://forums.unrealengine.com/t/how-to-check-if-a-point-is-reachable-by-pawn/367407/1 "2016-08-17T11:39:31Z")

</div>

Given a point on the NavMesh, how can I determine if an AI Pawn can reach this point?

Basically the player makes a noise at position (x,y,z), then I pass this (x,y,z) to the AI Pawn.

Currently the AI Pawn will always walk towards (x,y,z) even if it can’t reach it and when this happens it just stays still.

I’m looking for a function similar to Get Reachable Point In Radius, but to be given (x,y,z) and output a boolean as to whether the AI Pawn can reach (x,y,z) i.e. it’s not behind an impassable wall.

Attached image to help explain this

 ![103233-aipath.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/b/9/8b9a169532e05d6ea73df899e3031f134d17528c.png)

Cheers

---

<div class="post-metadata">

**Author:** ![indygoof](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@indygoof](https://forums.unrealengine.com/u/indygoof)\
**Post date:** [August 17, 2016, 2:07pm UTC](https://forums.unrealengine.com/t/how-to-check-if-a-point-is-reachable-by-pawn/367407/2 "2016-08-17T14:07:10Z")

</div>

Depends.

For a C++ Project:

```
UNavigationComponent* PathFindingComp = FindComponentByClass<UNavigationComponent>();
     if (PathFindingComp != NULL) {
         bool bFoundPath = PathFindingComp->FindPathToLocation(dest, NULL);
         if (bFoundPath == false || PathFindingComp->GetPath().IsValid() == false) {
             bFoundPath = PathFindingComp->FindSimplePathToLocation(dest);
         }
        if (!bFoundPath) {
             // display some error here or whatever
        }
     }

```

For a Blueprint only project: Good luck 😕

---

<div class="post-metadata">

**Author:** ![AlexDiru](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AlexDiru](https://forums.unrealengine.com/u/AlexDiru)\
**Post date:** [August 17, 2016, 2:58pm UTC](https://forums.unrealengine.com/t/how-to-check-if-a-point-is-reachable-by-pawn/367407/3 "2016-08-17T14:58:11Z")

</div>

It’s in BP but easy enough to write a custom node. Will give it a try, cheers 🙂

---

<div class="post-metadata">

**Author:** ![AlexDiru](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AlexDiru](https://forums.unrealengine.com/u/AlexDiru)\
**Post date:** [August 17, 2016, 3:15pm UTC](https://forums.unrealengine.com/t/how-to-check-if-a-point-is-reachable-by-pawn/367407/4 "2016-08-17T15:15:36Z")

</div>

Apparently UNavigationComponent is deprecated? I can’t seem to access the class and that’s what I found in a thread on google

---

<div class="post-metadata">

**Author:** ![indygoof](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@indygoof](https://forums.unrealengine.com/u/indygoof)\
**Post date:** [August 17, 2016, 3:55pm UTC](https://forums.unrealengine.com/t/how-to-check-if-a-point-is-reachable-by-pawn/367407/5 "2016-08-17T15:55:00Z")

</div>

Uh, sorry, didnt know that its deprecated. Will need to look for a current implementation.

---

<div class="post-metadata">

**Author:** ![AlexDiru](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AlexDiru](https://forums.unrealengine.com/u/AlexDiru)\
**Post date:** [August 17, 2016, 4:08pm UTC](https://forums.unrealengine.com/t/how-to-check-if-a-point-is-reachable-by-pawn/367407/6 "2016-08-17T16:08:33Z")

</div>

I’m trying with UNavigationSystem and then will try with UPathFollowingComponent. But I’m always sloooow with UE’s C++. Suggested code always seems to take ages to load suggestions - is that a problem on my end or just the size of the codebase?

---

<div class="post-metadata">

**Author:** ![AlexDiru](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AlexDiru](https://forums.unrealengine.com/u/AlexDiru)\
**Post date:** [August 17, 2016, 4:12pm UTC](https://forums.unrealengine.com/t/how-to-check-if-a-point-is-reachable-by-pawn/367407/7 "2016-08-17T16:12:41Z")

</div>

So far I have

```
UNavigationPath* NavPath = UNavigationSystem::FindPathToLocationSynchronously(GetWorld(), PathStart, Position, NULL);

```

But I’m not sure what to do with the NavPath (where PathStart is the actor location, Position is where to move to) and this is called from a class which extends the AIController

---

<div class="post-metadata">

**Author:** ![AlexDiru](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AlexDiru](https://forums.unrealengine.com/u/AlexDiru)\
**Post date:** [August 17, 2016, 4:13pm UTC](https://forums.unrealengine.com/t/how-to-check-if-a-point-is-reachable-by-pawn/367407/8 "2016-08-17T16:13:17Z")

</div>

For reproducibility, full code is:

```
UFUNCTION(BlueprintCallable, Category = "Midnight Sun BP Library")
	bool IsPositionReachable(FVector Position) {

		FVector PathStart = GetPawn()->GetActorLocation();

		UNavigationPath* NavPath = UNavigationSystem::FindPathToLocationSynchronously(GetWorld(), PathStart, Position, NULL);
		
		if (!NavPath)
			return false;

		
		return true;
	}
```

---

<div class="post-metadata">

**Author:** ![AlexDiru](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AlexDiru](https://forums.unrealengine.com/u/AlexDiru)\
**Post date:** [August 17, 2016, 4:25pm UTC](https://forums.unrealengine.com/t/how-to-check-if-a-point-is-reachable-by-pawn/367407/9 "2016-08-17T16:25:13Z")

</div>

I think I’ve solved it, gotta test a bit more

```
UFUNCTION(BlueprintCallable, Category = "Midnight Sun BP Library")
	bool IsPositionReachable(FVector Position) {

		FVector PathStart = GetPawn()->GetActorLocation();

		UNavigationPath* NavPath = UNavigationSystem::FindPathToLocationSynchronously(GetWorld(), PathStart, Position, NULL);
		
		if (!NavPath)
			return false;

		return NavPath->IsValid();
	}
```

---

<div class="post-metadata">

**Author:** ![AlexDiru](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AlexDiru](https://forums.unrealengine.com/u/AlexDiru)\
**Post date:** [August 17, 2016, 4:29pm UTC](https://forums.unrealengine.com/t/how-to-check-if-a-point-is-reachable-by-pawn/367407/10 "2016-08-17T16:29:17Z")

</div>

Nope I thought it worked, but it didn’t ☹

---

<div class="post-metadata">

**Author:** ![AlexDiru](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AlexDiru](https://forums.unrealengine.com/u/AlexDiru)\
**Post date:** [August 17, 2016, 4:39pm UTC](https://forums.unrealengine.com/t/how-to-check-if-a-point-is-reachable-by-pawn/367407/11 "2016-08-17T16:39:48Z")

</div>

Got it!

```
UFUNCTION(BlueprintCallable, Category = "Midnight Sun BP Library")
	bool IsPositionReachable(FVector Position) {
		FVector PathStart = GetPawn()->GetActorLocation();
		UNavigationPath* NavPath = UNavigationSystem::FindPathToLocationSynchronously(GetWorld(), PathStart, Position, NULL);
		
		if (!NavPath)
			return false;

		return !NavPath->IsPartial();
	}
```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_fa5b3096](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_fa5b3096](https://forums.unrealengine.com/u/anonymous_user_fa5b3096)\
**Post date:** [August 22, 2016, 1:14pm UTC](https://forums.unrealengine.com/t/how-to-check-if-a-point-is-reachable-by-pawn/367407/12 "2016-08-22T13:14:32Z")

</div>

I prefer using the test path function instead. It works + it’s a lot faster:

```
bool UNavigationSystem::TestPathSync(FPathFindingQuery Query, EPathFindingMode::Type Mode, int32* NumVisitedNodes)

```

The behavior tree decorator BTDecorator\_DoesPathExist uses that one if you want an example use.

---

<div class="post-metadata">

**Author:** ![AlexDiru](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AlexDiru](https://forums.unrealengine.com/u/AlexDiru)\
**Post date:** [August 22, 2016, 7:21pm UTC](https://forums.unrealengine.com/t/how-to-check-if-a-point-is-reachable-by-pawn/367407/13 "2016-08-22T19:21:38Z")

</div>

Thank you! 🙂 I’m guessing you are the same person on Reddit who helped me, so thank you x 2!

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_fa5b3096](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_fa5b3096](https://forums.unrealengine.com/u/anonymous_user_fa5b3096)\
**Post date:** [August 23, 2016, 12:11pm UTC](https://forums.unrealengine.com/t/how-to-check-if-a-point-is-reachable-by-pawn/367407/14 "2016-08-23T12:11:52Z")

</div>

You’re welcome 🙂 Same person.

The EQS will excel in this scenario also as the AI can pick a logical position instead of a random one. Plus it has the path test as an option ready to use 🙂

---

<div class="post-metadata">

**Author:** ![Jovimaca](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Jovimaca](https://forums.unrealengine.com/u/Jovimaca)\
**Post date:** [May 31, 2019, 10:07am UTC](https://forums.unrealengine.com/t/how-to-check-if-a-point-is-reachable-by-pawn/367407/15 "2019-05-31T10:07:33Z")

</div>

In my case I needed to check if NavPath was valid, my return is:

```
return NavPath != nullptr && NavPath->IsValid() && !NavPath->IsPartial();
```
