UNavigationSystemV1 Crashing when played

UNavigationSystemV1 * navSys = UNavigationSystemV1::GetCurrent(GetWorld());

if (!navSys)
	return;

UNavigationPath * path =  navSys->FindPathToLocationSynchronously(
	GetWorld(),
	GetOwner()->GetActorLocation(),
	location,
	GetOwner());

if (GEngine)
	GEngine->AddOnScreenDebugMessage(-1, 10, FColor::Red, "NUL");

/*if (path->PathPoints.Num() <= 0)
	return;*/

/*for (int32 i = 0; i < path->PathPoints.Num(); i++)
{
	UKismetSystemLibrary::DrawDebugArrow(
		GetWorld(),
		i == 0 ? GetOwner()->GetActorLocation() : path->PathPoints[i - 1],
		path->PathPoints[i],
		20.0f,
		FLinearColor::Green,
		15.0f,
		20);
}*/

It seems like navSys->FindPathToLocationSynchrounously is the one crashing but I do not know what is wrong with it. I run it this function on begin play so i can check if it calculating path correctly. please help i’ve been stuck with this for hours. I tried to dissect the code but somehow there is something wrong with FindPathToLocationSynchrounously. I also checked how other people use this.

Is your owner and world set? make some null checks. When it crashes like that its usually because its null.

You’re welcome.

When working with pointers, always have null checks and check if classes are valid!

Hi, Thank you for replying! you were right. my owner returns null. I changed it to GetCharacter() because my class is a controller. what a dumb mistake. I’ve been stuck here for hours. thanks! :slight_smile: