コード例 #1
0
void UNavigationComponent::DeferredRepathToGoal()
{
	GoalActor = RepathData.GoalActor.Get();
	CurrentGoal = RepathData.GoalLocation;
	bUseSimplePath = RepathData.bSimplePath;
	FMemory::MemZero<FDeferredRepath>(RepathData);

	const FVector GoalLocation = GoalActor ? GetCurrentMoveGoal(GoalActor, GetOwner()) : CurrentGoal;
	if (RePathTo(GoalLocation))
	{
		OriginalGoalActorLocation = GoalLocation;
	}
	else
	{
		FAIMessage::Send(Cast<AController>(GetOwner()), FAIMessage(UBrainComponent::AIMessage_RepathFailed, this));
	}
}
コード例 #2
0
void UNavigationComponent::TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction)
{
	// already requested not to tick. 
	if (bShoudTick == false)
	{
		return;
	}

	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

	check( GetOuter() != NULL );

	bool bSuccess = false;

	if (GoalActor != NULL)
	{
		const FVector GoalActorLocation = GetCurrentMoveGoal(GoalActor, GetOwner());
		const float DistanceSq = FVector::DistSquared(GoalActorLocation, OriginalGoalActorLocation);

		if (DistanceSq > RepathDistanceSq)
		{
			if (RePathTo(GoalActorLocation, StoredQueryFilter))
			{
				bSuccess = true;
				OriginalGoalActorLocation = GoalActorLocation;
			}
			else
			{
				FAIMessage::Send(Cast<AController>(GetOwner()), FAIMessage(UBrainComponent::AIMessage_RepathFailed, this));
			}
		}
		else
		{
			bSuccess = true;
		}
	}
	
	if (bSuccess == false)
	{
		ResetTransientData();
	}
}
コード例 #3
0
void UBTTask_RunEQSQuery::OnQueryFinished(TSharedPtr<struct FEnvQueryResult> Result)
{
	if (Result->Status == EEnvQueryStatus::Aborted)
	{
		return;
	}

	AActor* MyOwner = Cast<AActor>(Result->Owner.Get());
	if (APawn* PawnOwner = Cast<APawn>(MyOwner))
	{
		MyOwner = PawnOwner->GetController();
	}

	UBehaviorTreeComponent* MyComp = MyOwner ? MyOwner->FindComponentByClass<UBehaviorTreeComponent>() : NULL;
	if (!MyComp)
	{
		UE_LOG(LogBehaviorTree, Warning, TEXT("Unable to find behavior tree to notify about finished query from %s!"), *GetNameSafe(MyOwner));
		return;
	}

	bool bSuccess = (Result->Items.Num() == 1);
	if (bSuccess)
	{
		UBlackboardComponent* MyBlackboard = MyComp->GetBlackboardComponent();
		UEnvQueryItemType* ItemTypeCDO = (UEnvQueryItemType*)Result->ItemType->GetDefaultObject();

		bSuccess = ItemTypeCDO->StoreInBlackboard(BlackboardKey, MyBlackboard, Result->RawData.GetTypedData() + Result->Items[0].DataOffset);		
		if (!bSuccess)
		{
			UE_VLOG(MyOwner, LogBehaviorTree, Warning, TEXT("Failed to store query result! item:%s key:%s"),
				*UEnvQueryTypes::GetShortTypeName(Result->ItemType),
				*UBehaviorTreeTypes::GetShortTypeName(BlackboardKey.SelectedKeyType));
		}
	}

	FAIMessage::Send(MyComp, FAIMessage(UBrainComponent::AIMessage_QueryFinished, this, Result->QueryID, bSuccess));
}
コード例 #4
0
void UAIBlueprintHelperLibrary::SendAIMessage(APawn* Target, FName Message, UObject* MessageSource, bool bSuccess)
{
	FAIMessage::Send(Target, FAIMessage(Message, MessageSource, bSuccess));
}