Problem in making AI controller move

Hi everyone, I’m stuck in trying to visualize the navigation points and I can’t figure out why this error is happening:
I get an Exception when executing this code:

I write the following code in the beginPlay function of my character class:

this->PaladinAIController = Cast<AAIController>(GetController());
if(this->PaladinAIController && this->PaladinPatrolTarget)
{
    FAIMoveRequest MoveRequest;
    MoveRequest.SetGoalActor(PaladinPatrolTarget);
    MoveRequest.SetAcceptanceRadius(15.f);
    FNavPathSharedPtr NavPath;
    this->PaladinAIController->MoveTo(MoveRequest, &NavPath);

    TArray<FNavPathPoint>& PathPoints = NavPath->GetPathPoints();
    for(auto& Point: PathPoints)
    {
       const FVector& Location = Point.Location;
       DrawDebugSphere(GetWorld(), Location, 12.f, 12, FColor::Green, false, 10.f);
    }
}

Using the debugger, I could see that the error was on TArray<FNavPathPoint>& PathPoints = NavPath->GetPathPoints();

Where NavPath seemed to be null , but

The unreal engine crash states something like this:

Assertion failed: IsValid() [File:C:\Program Files\Epic Games\UE_5.3\Engine\Source\Runtime\Core\Public\Templates\SharedPointer.h] [Line: 1139]

UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_UnrealEd
UnrealEditor_UnrealEd
UnrealEditor_UnrealEd
UnrealEditor_UnrealEd
UnrealEditor_UnrealEd
UnrealEditor_UnrealEd
UnrealEditor_UnrealEd
UnrealEditor_UnrealEd
UnrealEditor
UnrealEditor
UnrealEditor
UnrealEditor
UnrealEditor
UnrealEditor
kernel32
ntdll

I double checked I have a nav mesh:

1 Like

我有同样的问题,请问你解决了吗?I have the same problem, have you solved it ? Thank you.

Hi! there.
Try to use this

	/** Finds path instantly, in a FindPath Synchronously. 
	 *	@param PathfindingContext could be one of following: NavigationData (like Navmesh actor), Pawn or Controller. This parameter determines parameters of specific pathfinding query */
	UFUNCTION(BlueprintCallable, Category = "AI|Navigation", meta = (WorldContext="WorldContextObject"))
	static NAVIGATIONSYSTEM_API UNavigationPath* FindPathToLocationSynchronously(UObject* WorldContextObject, const FVector& PathStart, const FVector& PathEnd, AActor* PathfindingContext = NULL, TSubclassOf<UNavigationQueryFilter> FilterClass = NULL);

I find it in “CropoutSampleProject”,/Game/Content/Blueprints/Core/Player/BP_Player,function “Update Path”.
Good luck!