0
\$\begingroup\$

I get an Exception when executing this code:

void PaladinClass::BeginPlay(){
Super::BeginPlay();

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 have also confirmed that I have a Navigation Mesh in the scene. Hence, I cannot seem to find the source of the issue. Any insights would be greatly appreciated.

\$\endgroup\$
2
  • \$\begingroup\$ @JackAidley, PaladinAIController->MoveTo(MoveRequest, &NavPath) is passing the NavPath as a reference, shouldn't this function be responsible for modifying the value of the navPath? \$\endgroup\$
    – mleu
    Commented May 5 at 10:39
  • \$\begingroup\$ Oh, you're right, I missed that when scanned the code. My bad. \$\endgroup\$ Commented May 5 at 10:56

1 Answer 1

0
\$\begingroup\$

NavPath is not set to anything if MoveTo does not find a path to the destination for whatever reason. You need to check the return value from MoveTo to ensure that a valid path has been found before using the returned VavPath for anything.

The return from MoveTo is of type FPathFollowingRequestResult which has a Code member. This is set to EPathFollowingRequestResult::RequestSuccessful when it worked and either ::Failed or ::AlreadyAtGoal otherwise.

\$\endgroup\$
1
  • \$\begingroup\$ you were correct, the result was returning ::Failed. But, the actor that is the target is inside the navMesh and there are no obstacles such that the path would be blocked. Should that be enough to let the result be successful? \$\endgroup\$
    – mleu
    Commented May 8 at 7:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .