[Bug] AI moves to 0,0,0 despite not being told to

I’m scripting my AI in Blueprint. I’ve created an AI state where the AI wanders to a random point in a circle. It works very well until, occasionally, my AI will attempt to move to 0,0,0. There’s nothing in my blueprint telling him to do that.

I “watched” the destination variable state something like "Current Value = (X= 472.0, Y= -1842.0, Z= 154.0), even thought the AI is off sitting above 0,0,0.

This occurs with both the AI Move To and the Move to Location nodes. It also happens at seemingly random times. Sometimes it occurs right away, other times I have to watch him for like 10 minutes.

Any ideas?

Yeah, there was a bug in UPathFollowingComponent::DetermineStartingPathPoint. It’s fixed on main branch, but if you don’t want to sync and have access to C++ code make sure it looks like this:

int32 UPathFollowingComponent::DetermineStartingPathPoint(const FNavigationPath* ConsideredPath) const
{
	int32 PickedPathPoint = INDEX_NONE;

	if (ConsideredPath && ConsideredPath->IsValid())
	{
		// if we already have some info on where we were on previous path
		// we can find out if there's a segment on new path we're currently at
		if (MoveSegmentStartRef != INVALID_NAVNODEREF &&
			MoveSegmentEndRef != INVALID_NAVNODEREF &&
			ConsideredPath->GetOwner() != NULL)
		{
			// iterate every new path node and see if segment match
			for (int32 PathPoint = 0; PathPoint < ConsideredPath->PathPoints.Num() - 1; ++PathPoint)
			{
				if (ConsideredPath->PathPoints[PathPoint].NodeRef == MoveSegmentStartRef && 
					ConsideredPath->PathPoints[PathPoint+1].NodeRef == MoveSegmentEndRef)
				{
					PickedPathPoint = PathPoint;
					break;
				}
			}
		}

		if (MovementComp && PickedPathPoint == INDEX_NONE)
		{
			if (ConsideredPath->PathPoints.Num() > 2)
			{
				// check if is closer to first or second path point (don't assume AI's standing)
				const FVector CurrentLocation = MovementComp->GetActorFeetLocation();
				const float SqDistToFirstPoint = FVector::DistSquared(CurrentLocation, ConsideredPath->PathPoints[0].Location);
				const float SqDistToSecondPoint = FVector::DistSquared(CurrentLocation, ConsideredPath->PathPoints[1].Location);
				PickedPathPoint = (SqDistToFirstPoint < SqDistToSecondPoint) ? 0 : 1;
			}
			else
			{
				// If there are only two point we probably should start from the beginning
				PickedPathPoint = 0;
			}
		}
	}

	return PickedPathPoint;
}

If you don’t have access to C++ or just don’t want to mess around with it just wait for 4.2. Either way let me know if it’s still happening to you :slight_smile:

Cheers,

–mieszko

Will do. Thanks! I’ll probably wait for 4.2 Trying to do everything in blueprint.

Hello,

Thank you for your report. We were not able to investigate this on the engine version you reported, but there have been many version changes to UE4 since this question was first posted. With a new version of the Engine comes new fixes and it is possible that this issue has changed or may no longer occur. Due to timetable of when this issue was first posted, we are marking this post as resolved for tracking purposes.

If you are still experiencing the issue you reported in the current engine version, then please respond to this message with additional information and we will investigate as soon as possible. If you are experiencing a similar, but different issue at this time, please submit a new report for it.

Thank you!