bool UBTDecorator_IsAtLocation::CalculateRawConditionValue(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) const
{
	bool bHasReached = false;

	AAIController* AIOwner = OwnerComp.GetAIOwner();
	UPathFollowingComponent* PathFollowingComponent = AIOwner ? AIOwner->GetPathFollowingComponent() : nullptr;
	if (PathFollowingComponent)
	{
		const UBlackboardComponent* MyBlackboard = OwnerComp.GetBlackboardComponent();

		if (BlackboardKey.SelectedKeyType == UBlackboardKeyType_Object::StaticClass())
		{
			UObject* KeyValue = MyBlackboard->GetValue<UBlackboardKeyType_Object>(BlackboardKey.GetSelectedKeyID());
			AActor* TargetActor = Cast<AActor>(KeyValue);
			if (TargetActor)
			{
				bHasReached = PathFollowingComponent->HasReached(*TargetActor, AcceptableRadius, false, bUseNavAgentGoalLocation);
			}
		}
		else if (BlackboardKey.SelectedKeyType == UBlackboardKeyType_Vector::StaticClass())
		{
			const FVector TargetLocation = MyBlackboard->GetValue<UBlackboardKeyType_Vector>(BlackboardKey.GetSelectedKeyID());
			if (FAISystem::IsValidLocation(TargetLocation))
			{
				bHasReached = PathFollowingComponent->HasReached(TargetLocation, AcceptableRadius);
			}
		}
	}

	return bHasReached;
}
Ejemplo n.º 2
0
void AController::UpdateNavigationComponents()
{
	UPathFollowingComponent* PathFollowingComp = FindComponentByClass<UPathFollowingComponent>();
	if (PathFollowingComp != NULL)
	{
		PathFollowingComp->UpdateCachedComponents();
	}
}
Ejemplo n.º 3
0
void AController::StopMovement()
{
	UE_VLOG(this, LogNavigation, Log, TEXT("AController::StopMovement: %s STOP MOVEMENT"), *GetNameSafe(GetPawn()));

	UPathFollowingComponent* PathFollowingComp = FindComponentByClass<UPathFollowingComponent>();
	if (PathFollowingComp != NULL)
	{
		PathFollowingComp->AbortMove(TEXT("StopMovement"));
	}
}
Ejemplo n.º 4
0
void ANavLinkProxy::ResumePathFollowing(AActor* Agent)
{
	if (Agent)
	{
		UPathFollowingComponent* PathComp = Agent->FindComponentByClass<UPathFollowingComponent>();
		if (PathComp == NULL)
		{
			APawn* PawnOwner = Cast<APawn>(Agent);
			if (PawnOwner && PawnOwner->GetController())
			{
				PathComp = PawnOwner->GetController()->FindComponentByClass<UPathFollowingComponent>();
			}
		}

		if (PathComp)
		{
			PathComp->FinishUsingCustomLink(SmartLinkComp);
		}
	}
}
Ejemplo n.º 5
0
void UAITask_MoveTo::OnDestroy(bool bInOwnerFinished)
{
	Super::OnDestroy(bInOwnerFinished);
	
	ResetObservers();
	ResetTimers();

	if (MoveRequestID.IsValid())
	{
		UPathFollowingComponent* PFComp = OwnerController ? OwnerController->GetPathFollowingComponent() : nullptr;
		if (PFComp && PFComp->GetStatus() != EPathFollowingStatus::Idle)
		{
			PFComp->AbortMove(*this, FPathFollowingResultFlags::OwnerFinished, MoveRequestID);
		}
	}

	// clear the shared pointer now to make sure other systems
	// don't think this path is still being used
	Path = nullptr;
}
Ejemplo n.º 6
0
void AController::UpdateNavigationComponents()
{
	UNavigationComponent* PathFindingComp = FindComponentByClass<UNavigationComponent>();
	if (PathFindingComp != NULL)
	{
		PathFindingComp->OnNavAgentChanged();
		PathFindingComp->UpdateCachedComponents();
	}

	UPathFollowingComponent* PathFollowingComp = FindComponentByClass<UPathFollowingComponent>();
	if (PathFollowingComp != NULL)
	{
		PathFollowingComp->UpdateCachedComponents();
	}

	// initialize movement mode in characters
	ACharacter* MyCharacter = Cast<ACharacter>(GetPawn());
	if (MyCharacter && MyCharacter->CharacterMovement)
	{
		MyCharacter->CharacterMovement->SetDefaultMovementMode();
	}
}
Ejemplo n.º 7
0
void UAITask_MoveTo::FinishMoveTask(EPathFollowingResult::Type InResult)
{
	if (MoveRequestID.IsValid())
	{
		UPathFollowingComponent* PFComp = OwnerController ? OwnerController->GetPathFollowingComponent() : nullptr;
		if (PFComp && PFComp->GetStatus() != EPathFollowingStatus::Idle)
		{
			ResetObservers();
			PFComp->AbortMove(*this, FPathFollowingResultFlags::OwnerFinished, MoveRequestID);
		}
	}

	MoveResult = InResult;
	EndTask();

	if (InResult == EPathFollowingResult::Invalid)
	{
		OnRequestFailed.Broadcast();
	}
	else
	{
		OnMoveFinished.Broadcast(InResult);
	}
}
void FGameplayDebuggerCategory_AI::CollectPathData(AAIController* DebugAI)
{
	UPathFollowingComponent* PathComp = DebugAI ? DebugAI->GetPathFollowingComponent() : nullptr;
	DataPack.bIsUsingPathFollowing = (PathComp != nullptr);

	if (PathComp)
	{
		TArray<FString> Tokens;
		TArray<EPathFollowingDebugTokens::Type> Flags;
		PathComp->GetDebugStringTokens(Tokens, Flags);

		for (int32 Idx = 0; Idx < Tokens.Num(); Idx++)
		{
			switch (Flags[Idx])
			{
			case EPathFollowingDebugTokens::Description:
				DataPack.PathFollowingInfo += Tokens[Idx];
				break;

			case EPathFollowingDebugTokens::ParamName:
				DataPack.PathFollowingInfo += TEXT(", {yellow}");
				DataPack.PathFollowingInfo += Tokens[Idx];
				DataPack.PathFollowingInfo += TEXT(":");
				break;

			case EPathFollowingDebugTokens::PassedValue:
				DataPack.PathFollowingInfo += TEXT("{yellow}");
				DataPack.PathFollowingInfo += Tokens[Idx];
				break;

			case EPathFollowingDebugTokens::FailedValue:
				DataPack.PathFollowingInfo += TEXT("{orange}");
				DataPack.PathFollowingInfo += Tokens[Idx];
				break;

			default:
				break;
			}
		}

		FNavigationPath* CurrentPath = PathComp->GetPath().Get();
		if (CurrentPath)
		{
			DataPack.bPathHasGoalActor = (CurrentPath->GetGoalActor() != nullptr);
			DataPack.PathGoalLocation = CurrentPath->GetGoalLocation();
			DataPack.NextPathPointIndex = PathComp->GetNextPathIndex();
		}

		if ((CurrentPath != RawLastPath) || (CurrentPath && (CurrentPath->GetLastUpdateTime() != LastPathUpdateTime) ))
		{
			RawLastPath = CurrentPath;
			PathDataPack = FRepDataPath();

			if (CurrentPath)
			{
				LastPathUpdateTime = CurrentPath->GetLastUpdateTime();

				const FNavMeshPath* NavMeshPath = CurrentPath->CastPath<FNavMeshPath>();
				const ARecastNavMesh* NavData = Cast<const ARecastNavMesh>(CurrentPath->GetNavigationDataUsed());
				if (NavMeshPath && NavData)
				{
					for (int32 Idx = 0; Idx < NavMeshPath->PathCorridor.Num(); Idx++)
					{
						FRepDataPath::FPoly PolyData;
						NavData->GetPolyVerts(NavMeshPath->PathCorridor[Idx], PolyData.Points);
						
						const uint32 AreaId = NavData->GetPolyAreaID(NavMeshPath->PathCorridor[Idx]);
						PolyData.Color = NavData->GetAreaIDColor(AreaId);

						PathDataPack.PathCorridor.Add(PolyData);
					}
				}

				for (int32 Idx = 0; Idx < CurrentPath->GetPathPoints().Num(); Idx++)
				{
					PathDataPack.PathPoints.Add(CurrentPath->GetPathPoints()[Idx].Location);
				}
			}
		}
	}
}
Ejemplo n.º 9
0
bool AController::IsFollowingAPath() const
{
	UPathFollowingComponent* PathFollowingComp = FindComponentByClass<UPathFollowingComponent>();
	return (PathFollowingComp != nullptr) && PathFollowingComp->HasValidPath();
}