2022-09-28 01:06:15 -04:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
2021-11-24 04:26:12 -05:00
|
|
|
|
|
|
|
|
#include "Blueprint/StateTreeTaskBlueprintBase.h"
|
2023-01-19 00:48:07 -05:00
|
|
|
#include "Blueprint/StateTreeNodeBlueprintBase.h"
|
2021-11-24 04:26:12 -05:00
|
|
|
#include "StateTreeExecutionContext.h"
|
2022-09-19 19:47:11 -04:00
|
|
|
#include "BlueprintNodeHelpers.h"
|
2021-11-24 04:26:12 -05:00
|
|
|
|
2022-09-28 01:06:15 -04:00
|
|
|
#include UE_INLINE_GENERATED_CPP_BY_NAME(StateTreeTaskBlueprintBase)
|
|
|
|
|
|
2021-11-24 04:26:12 -05:00
|
|
|
//----------------------------------------------------------------------//
|
|
|
|
|
// UStateTreeTaskBlueprintBase
|
|
|
|
|
//----------------------------------------------------------------------//
|
|
|
|
|
|
2022-09-19 19:47:11 -04:00
|
|
|
UStateTreeTaskBlueprintBase::UStateTreeTaskBlueprintBase(const FObjectInitializer& ObjectInitializer)
|
|
|
|
|
: Super(ObjectInitializer)
|
2022-11-01 15:11:19 -04:00
|
|
|
, bShouldStateChangeOnReselect(true)
|
2022-11-22 06:18:24 -05:00
|
|
|
, bShouldCallTick(true)
|
2022-11-01 15:11:19 -04:00
|
|
|
, bShouldCallTickOnlyOnEvents(false)
|
2022-11-18 08:38:31 -05:00
|
|
|
, bShouldCopyBoundPropertiesOnTick(true)
|
|
|
|
|
, bShouldCopyBoundPropertiesOnExitState(true)
|
2021-11-24 04:26:12 -05:00
|
|
|
{
|
2022-09-19 19:47:11 -04:00
|
|
|
bHasEnterState = BlueprintNodeHelpers::HasBlueprintFunction(TEXT("ReceiveEnterState"), *this, *StaticClass());
|
|
|
|
|
bHasExitState = BlueprintNodeHelpers::HasBlueprintFunction(TEXT("ReceiveExitState"), *this, *StaticClass());
|
|
|
|
|
bHasStateCompleted = BlueprintNodeHelpers::HasBlueprintFunction(TEXT("ReceiveStateCompleted"), *this, *StaticClass());
|
|
|
|
|
bHasTick = BlueprintNodeHelpers::HasBlueprintFunction(TEXT("ReceiveTick"), *this, *StaticClass());
|
2021-11-24 04:26:12 -05:00
|
|
|
}
|
|
|
|
|
|
2022-09-28 09:55:53 -04:00
|
|
|
EStateTreeRunStatus UStateTreeTaskBlueprintBase::EnterState(FStateTreeExecutionContext& Context, const FStateTreeTransitionResult& Transition)
|
2021-11-24 04:26:12 -05:00
|
|
|
{
|
2022-12-05 09:16:37 -05:00
|
|
|
// Task became active, cache event queue and owner.
|
2023-01-23 12:48:04 -05:00
|
|
|
SetCachedInstanceDataFromContext(Context);
|
2022-12-05 09:16:37 -05:00
|
|
|
|
2022-09-19 19:47:11 -04:00
|
|
|
if (bHasEnterState)
|
|
|
|
|
{
|
2022-09-28 09:55:53 -04:00
|
|
|
return ReceiveEnterState(Transition);
|
2022-09-19 19:47:11 -04:00
|
|
|
}
|
|
|
|
|
return EStateTreeRunStatus::Running;
|
2021-11-24 04:26:12 -05:00
|
|
|
}
|
|
|
|
|
|
2022-09-28 09:55:53 -04:00
|
|
|
void UStateTreeTaskBlueprintBase::ExitState(FStateTreeExecutionContext& Context, const FStateTreeTransitionResult& Transition)
|
2021-11-24 04:26:12 -05:00
|
|
|
{
|
2022-09-19 19:47:11 -04:00
|
|
|
if (bHasExitState)
|
|
|
|
|
{
|
2022-09-28 09:55:53 -04:00
|
|
|
ReceiveExitState(Transition);
|
2022-09-19 19:47:11 -04:00
|
|
|
}
|
2022-12-05 09:16:37 -05:00
|
|
|
|
|
|
|
|
// Task became inactive, clear cached event queue and owner.
|
2023-01-23 12:48:04 -05:00
|
|
|
ClearCachedInstanceData();
|
2021-11-24 04:26:12 -05:00
|
|
|
}
|
|
|
|
|
|
2022-04-05 03:20:57 -04:00
|
|
|
void UStateTreeTaskBlueprintBase::StateCompleted(FStateTreeExecutionContext& Context, const EStateTreeRunStatus CompletionStatus, const FStateTreeActiveStates& CompletedActiveStates)
|
2021-11-24 04:26:12 -05:00
|
|
|
{
|
2022-09-19 19:47:11 -04:00
|
|
|
if (bHasStateCompleted)
|
|
|
|
|
{
|
|
|
|
|
ReceiveStateCompleted(CompletionStatus, CompletedActiveStates);
|
|
|
|
|
}
|
2021-11-24 04:26:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EStateTreeRunStatus UStateTreeTaskBlueprintBase::Tick(FStateTreeExecutionContext& Context, const float DeltaTime)
|
|
|
|
|
{
|
2022-09-19 19:47:11 -04:00
|
|
|
if (bHasTick)
|
|
|
|
|
{
|
|
|
|
|
return ReceiveTick(DeltaTime);
|
|
|
|
|
}
|
|
|
|
|
return EStateTreeRunStatus::Running;
|
2021-11-24 04:26:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------//
|
|
|
|
|
// FStateTreeBlueprintTaskWrapper
|
|
|
|
|
//----------------------------------------------------------------------//
|
|
|
|
|
|
2022-11-18 08:38:31 -05:00
|
|
|
EDataValidationResult FStateTreeBlueprintTaskWrapper::Compile(FStateTreeDataView InstanceDataView, TArray<FText>& ValidationMessages)
|
|
|
|
|
{
|
|
|
|
|
const UStateTreeTaskBlueprintBase& InstanceData = InstanceDataView.Get<UStateTreeTaskBlueprintBase>();
|
|
|
|
|
|
|
|
|
|
// Copy over ticking related options.
|
|
|
|
|
bShouldStateChangeOnReselect = InstanceData.bShouldStateChangeOnReselect;
|
2022-11-22 06:18:24 -05:00
|
|
|
bShouldCallTick = InstanceData.bShouldCallTick || InstanceData.bHasTick;
|
2022-11-18 08:38:31 -05:00
|
|
|
bShouldCallTickOnlyOnEvents = InstanceData.bShouldCallTickOnlyOnEvents;
|
|
|
|
|
bShouldCopyBoundPropertiesOnTick = InstanceData.bShouldCopyBoundPropertiesOnTick;
|
|
|
|
|
bShouldCopyBoundPropertiesOnExitState = InstanceData.bShouldCopyBoundPropertiesOnExitState;
|
|
|
|
|
|
|
|
|
|
return EDataValidationResult::Valid;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-28 09:55:53 -04:00
|
|
|
EStateTreeRunStatus FStateTreeBlueprintTaskWrapper::EnterState(FStateTreeExecutionContext& Context, const FStateTreeTransitionResult& Transition) const
|
2021-11-24 04:26:12 -05:00
|
|
|
{
|
2022-09-01 09:06:53 -04:00
|
|
|
UStateTreeTaskBlueprintBase* Instance = Context.GetInstanceDataPtr<UStateTreeTaskBlueprintBase>(*this);
|
2021-11-24 04:26:12 -05:00
|
|
|
check(Instance);
|
2022-11-18 08:38:31 -05:00
|
|
|
return Instance->EnterState(Context, Transition);
|
2021-11-24 04:26:12 -05:00
|
|
|
}
|
|
|
|
|
|
2022-09-28 09:55:53 -04:00
|
|
|
void FStateTreeBlueprintTaskWrapper::ExitState(FStateTreeExecutionContext& Context, const FStateTreeTransitionResult& Transition) const
|
2021-11-24 04:26:12 -05:00
|
|
|
{
|
2022-09-01 09:06:53 -04:00
|
|
|
UStateTreeTaskBlueprintBase* Instance = Context.GetInstanceDataPtr<UStateTreeTaskBlueprintBase>(*this);
|
2021-11-24 04:26:12 -05:00
|
|
|
check(Instance);
|
2022-11-18 08:38:31 -05:00
|
|
|
Instance->ExitState(Context, Transition);
|
2021-11-24 04:26:12 -05:00
|
|
|
}
|
|
|
|
|
|
2022-04-05 03:20:57 -04:00
|
|
|
void FStateTreeBlueprintTaskWrapper::StateCompleted(FStateTreeExecutionContext& Context, const EStateTreeRunStatus CompletionStatus, const FStateTreeActiveStates& CompletedActiveStates) const
|
2021-11-24 04:26:12 -05:00
|
|
|
{
|
2022-09-01 09:06:53 -04:00
|
|
|
UStateTreeTaskBlueprintBase* Instance = Context.GetInstanceDataPtr<UStateTreeTaskBlueprintBase>(*this);
|
2021-11-24 04:26:12 -05:00
|
|
|
check(Instance);
|
2022-04-05 03:20:57 -04:00
|
|
|
Instance->StateCompleted(Context, CompletionStatus, CompletedActiveStates);
|
2021-11-24 04:26:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EStateTreeRunStatus FStateTreeBlueprintTaskWrapper::Tick(FStateTreeExecutionContext& Context, const float DeltaTime) const
|
|
|
|
|
{
|
2022-09-01 09:06:53 -04:00
|
|
|
UStateTreeTaskBlueprintBase* Instance = Context.GetInstanceDataPtr<UStateTreeTaskBlueprintBase>(*this);
|
2021-11-24 04:26:12 -05:00
|
|
|
check(Instance);
|
2022-11-18 08:38:31 -05:00
|
|
|
return Instance->Tick(Context, DeltaTime);
|
2021-11-24 04:26:12 -05:00
|
|
|
}
|
2022-09-28 01:06:15 -04:00
|
|
|
|