Hello!
I’ve wanted to create a simple patrol movement between two simple actors with location that point to eachother. I managed to do it earlier, but for some reason it doesn’t work right now. I have the simple path actor set up and the AI character is moving towards it, but once the character overlaps with that simple actor, it will stand on it and the move node won’t finish.
I’ve tracked and debugged the MoveTo node code.
If I understand right “bAlreadyAtGoal” in AAIController::MoveTo function should finish the MoveTo execution, so two cases that can affect it are on the line:
bAlreadyAtGoal = bCanRequestMove && PathFollowingComponent->HasReached(MoveRequest);
bCanRequestMove should be true whenever movement happens, but PathFollowingComponent->HasReached(MoveRequest) checks if I already reached the goal, but seemingly it returns false, because bAlreadyAtGoal is never true and statement gets never called.
if (bAlreadyAtGoal)
{
UE_VLOG(this, LogAINavigation, Log, TEXT("MoveTo: already at goal!"));
ResultData.MoveId = PathFollowingComponent->RequestMoveWithImmediateFinish(EPathFollowingResult::Success);
ResultData.Code = EPathFollowingRequestResult::AlreadyAtGoal;
}
UPathFollowingComponent::HasReached function it’s reachmode is EPathFollowingReachMode::OverlapAgentAndGoal.
bool UPathFollowingComponent::HasReached(const FAIMoveRequest& MoveRequest) const
{
const EPathFollowingReachMode ReachMode = MoveRequest.IsReachTestIncludingAgentRadius() ?
(MoveRequest.IsReachTestIncludingGoalRadius() ? EPathFollowingReachMode::OverlapAgentAndGoal : EPathFollowingReachMode::OverlapAgent) :
(MoveRequest.IsReachTestIncludingGoalRadius() ? EPathFollowingReachMode::OverlapGoal : EPathFollowingReachMode::ExactLocation);
return MoveRequest.IsMoveToActorRequest() ?
(MoveRequest.GetGoalActor() ? HasReached(*MoveRequest.GetGoalActor(), ReachMode, MoveRequest.GetAcceptanceRadius()) : false) :
HasReached(MoveRequest.GetGoalLocation(), ReachMode, MoveRequest.GetAcceptanceRadius());
}
In the return statement **MoveRequest.IsMoveToActorRequest()** returns always true. So it always enter this statement:
(MoveRequest.GetGoalActor() ? HasReached(*MoveRequest.GetGoalActor(), ReachMode, MoveRequest.GetAcceptanceRadius()) : false)
And **MoveRequest.GetGoalActor()** never returns nullptr. So it always enters this function:
HasReached(*MoveRequest.GetGoalActor(), ReachMode, MoveRequest.GetAcceptanceRadius())
Next, through HasReached function UPathFollowingComponent::HasReachedInternal is called, which never returns true (which would be neccessary to finish MoveTo execution), although when I debugged whether AI character is close to the goalactor, it doesn't return false. It's a mystery for me.
I have no idea what could cause this strange behavior. If you need more information about that, feel free to ask.
With regards.
Waiting for you response.