void UNavigationComponent::NotifyPathUpdate()
{
	UE_VLOG(GetOwner(), LogNavigation, Log, TEXT("NotifyPathUpdate points:%d valid:%s"),
		Path.IsValid() ? Path->PathPoints.Num() : 0,
		Path.IsValid() ? (Path->IsValid() ? TEXT("yes") : TEXT("no")) : TEXT("missing!"));

	if (MyPathObserver != NULL)
	{
		MyPathObserver->OnPathUpdated(this);
	}

	if (PathFollowComp && bNotifyPathFollowing)
	{
		PathFollowComp->UpdateMove(Path);
	}

	if (!Path.IsValid() || !Path->IsValid())
	{	// If pointer is valid, nav-path is not.  Print information so we'll know exactly what went wrong when we hit the check below.
		UE_CVLOG(Path.IsValid(), GetOwner(), LogNavigation, Warning,
		TEXT("NotifyPathUpdate fetched invalid NavPath!  NavPath has %d points, is%sready, and is%sup-to-date"),
		Path->PathPoints.Num(), Path->IsReady() ? TEXT(" ") : TEXT(" NOT "), Path->IsUpToDate() ? TEXT(" ") : TEXT(" NOT ")	);

		ResetTransientData();
	}
}
void UAITask_MoveTo::Resume()
{
	Super::Resume();

	if (!MoveRequestID.IsValid() || !OwnerController->ResumeMove(MoveRequestID))
	{
		UE_CVLOG(MoveRequestID.IsValid(), GetGameplayTasksComponent(), LogGameplayTasks, Log, TEXT("%s> Resume move failed, starting new one."), *GetName());
		ConditionalPerformMove();
	}
}
void AAIController::UnclaimTaskResource(TSubclassOf<UGameplayTaskResource> ResourceClass)
{
    if (CachedGameplayTasksComponent)
    {
        const uint8 ResourceID = UGameplayTaskResource::GetResourceID(ResourceClass);
        if (ScriptClaimedResources.HasID(ResourceID) == true)
        {
            ScriptClaimedResources.RemoveID(ResourceID);

            UE_VLOG(this, LogGameplayTasks, Log, TEXT("UnclaimTaskResource %s"), *GetNameSafe(*ResourceClass));

            UGameplayTask* ResourceTask = CachedGameplayTasksComponent->FindResourceConsumingTaskByName(ResourceClass->GetFName());
            if (ResourceTask)
            {
                ResourceTask->EndTask();
            }
            UE_CVLOG(ResourceTask == nullptr, this, LogGameplayTasks, Warning, TEXT("UnclaimTaskResource failed to find UGameplayTask_ClaimResource instance"));
        }
    }
}
Exemple #4
0
bool UPawnAction::PushChildAction(UPawnAction& Action)
{
	bool bResult = false;
	
	if (OwnerComponent != NULL)
	{
		UE_CVLOG( ChildAction != NULL
			, GetPawn(), LogPawnAction, Log, TEXT("%s> Pushing child action %s while already having ChildAction set to %s")
			, *GetName(), *Action.GetName(), *ChildAction->GetName());
		
		// copy runtime data
		// note that priority and instigator will get assigned as part of PushAction.

		bResult = OwnerComponent->PushAction(Action, GetPriority(), Instigator);

		// adding a check to make sure important data has been set 
		ensure(Action.GetPriority() == GetPriority() && Action.GetInstigator() == GetInstigator());
	}

	return bResult;
}
void AAIController::ClaimTaskResource(TSubclassOf<UGameplayTaskResource> ResourceClass)
{
    if (CachedGameplayTasksComponent)
    {
        const uint8 ResourceID = UGameplayTaskResource::GetResourceID(ResourceClass);
        if (ScriptClaimedResources.HasID(ResourceID) == false)
        {
            ScriptClaimedResources.AddID(ResourceID);

            UE_VLOG(this, LogGameplayTasks, Log, TEXT("ClaimTaskResource %s"), *GetNameSafe(*ResourceClass));

            IGameplayTaskOwnerInterface& AsTaskOwner = *this;
            UGameplayTask_ClaimResource* ResourceTask = UGameplayTask_ClaimResource::ClaimResource(AsTaskOwner, ResourceClass, uint8(EAITaskPriority::High), ResourceClass->GetFName());
            if (ResourceTask)
            {
                CachedGameplayTasksComponent->AddTaskReadyForActivation(*ResourceTask);
            }
            UE_CVLOG(ResourceTask == nullptr, this, LogGameplayTasks, Warning, TEXT("ClaimTaskResource failed to create UGameplayTask_ClaimResource instance"));
        }
    }
}
void FVisualLogger::Redirect(UObject* FromObject, UObject* ToObject)
{
	if (FromObject == ToObject || FromObject == nullptr || ToObject == nullptr)
	{
		return;
	}

	UObject* OldRedirection = FindRedirection(FromObject);
	UObject* NewRedirection = FindRedirection(ToObject);

	if (OldRedirection != NewRedirection)
	{
		auto OldArray = RedirectionMap.Find(OldRedirection);
		if (OldArray)
		{
			OldArray->RemoveSingleSwap(FromObject);
		}

		RedirectionMap.FindOrAdd(NewRedirection).AddUnique(FromObject);

		UE_CVLOG(FromObject != nullptr, FromObject, LogVisual, Log, TEXT("Redirected '%s' to '%s'"), *FromObject->GetName(), *NewRedirection->GetName());
	}
}
int32 FEQSParametrizedQueryExecutionRequest::Execute(AActor& QueryOwner, const UBlackboardComponent* BlackboardComponent, FQueryFinishedSignature& QueryFinishedDelegate)
{
	if (bUseBBKeyForQueryTemplate)
	{
		check(BlackboardComponent);

		// set QueryTemplate to contents of BB key
		UObject* QueryTemplateObject = BlackboardComponent->GetValue<UBlackboardKeyType_Object>(EQSQueryBlackboardKey.GetSelectedKeyID());
		QueryTemplate = Cast<UEnvQuery>(QueryTemplateObject);

		UE_CVLOG(QueryTemplate == nullptr, &QueryOwner, LogBehaviorTree, Warning, TEXT("Trying to run EQS query configured to use BB key, but indicated key (%s) doesn't contain EQS template pointer")
			, *EQSQueryBlackboardKey.SelectedKeyName.ToString());
	}

	if (QueryTemplate != nullptr)
	{
		FEnvQueryRequest QueryRequest(QueryTemplate, &QueryOwner);
		if (QueryConfig.Num() > 0)
		{
			// resolve 
			for (FAIDynamicParam& RuntimeParam : QueryConfig)
			{
				// check if given param requires runtime resolve, like reading from BB
				if (RuntimeParam.BBKey.IsSet())
				{
					check(BlackboardComponent && "If BBKey.IsSet and there's no BB component then we\'re in the error land!");

					// grab info from BB
					switch (RuntimeParam.ParamType)
					{
					case EAIParamType::Float:
					{
						const float Value = BlackboardComponent->GetValue<UBlackboardKeyType_Float>(RuntimeParam.BBKey.GetSelectedKeyID());
						QueryRequest.SetFloatParam(RuntimeParam.ParamName, Value);
					}
					break;
					case EAIParamType::Int:
					{
						const int32 Value = BlackboardComponent->GetValue<UBlackboardKeyType_Int>(RuntimeParam.BBKey.GetSelectedKeyID());
						QueryRequest.SetIntParam(RuntimeParam.ParamName, Value);
					}
					break;
					case EAIParamType::Bool:
					{
						const bool Value = BlackboardComponent->GetValue<UBlackboardKeyType_Bool>(RuntimeParam.BBKey.GetSelectedKeyID());
						QueryRequest.SetBoolParam(RuntimeParam.ParamName, Value);
					}
					break;
					default:
						checkNoEntry();
						break;
					}
				}
				else
				{
					switch (RuntimeParam.ParamType)
					{
					case EAIParamType::Float:
					{
						QueryRequest.SetFloatParam(RuntimeParam.ParamName, RuntimeParam.Value);
					}
					break;
					case EAIParamType::Int:
					{
						QueryRequest.SetIntParam(RuntimeParam.ParamName, RuntimeParam.Value);
					}
					break;
					case EAIParamType::Bool:
					{
						bool Result = RuntimeParam.Value > 0;
						QueryRequest.SetBoolParam(RuntimeParam.ParamName, Result);
					}
					break;
					default:
						checkNoEntry();
						break;
					}
				}
			}
		}

		return QueryRequest.Execute(RunMode, QueryFinishedDelegate);
	}

	return INDEX_NONE;
}