Files
UnrealEngineUWP/Engine/Plugins/Runtime/StateTree/Source/StateTreeModule/Private/Blueprint/StateTreeConditionBlueprintBase.cpp
mikko mononen a41a8c85f8 StateTree: extend when BP nodes can send events
- cache event queue for the whole active duration of the nodes
- this allows events to be sent outside tick (e.g. from delegate callbacks)

#preflight 638deb98c0652bbec2df9368

[CL 23389834 by mikko mononen in ue5-main branch]
2022-12-05 09:16:37 -05:00

48 lines
1.5 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "Blueprint/StateTreeConditionBlueprintBase.h"
#include "CoreMinimal.h"
#include "StateTreeExecutionContext.h"
#include "BlueprintNodeHelpers.h"
#include UE_INLINE_GENERATED_CPP_BY_NAME(StateTreeConditionBlueprintBase)
//----------------------------------------------------------------------//
// UStateTreeConditionBlueprintBase
//----------------------------------------------------------------------//
UStateTreeConditionBlueprintBase::UStateTreeConditionBlueprintBase(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
bHasTestCondition = BlueprintNodeHelpers::HasBlueprintFunction(TEXT("ReceiveTestCondition"), *this, *StaticClass());
}
bool UStateTreeConditionBlueprintBase::TestCondition(FStateTreeExecutionContext& Context) const
{
if (bHasTestCondition)
{
// Cache the owner and event queue for the duration the condition is evaluated.
SetCachedEventQueueFromContext(Context);
const bool bResult = ReceiveTestCondition();
ClearCachedEventQueue();
return bResult;
}
return false;
}
//----------------------------------------------------------------------//
// FStateTreeBlueprintConditionWrapper
//----------------------------------------------------------------------//
bool FStateTreeBlueprintConditionWrapper::TestCondition(FStateTreeExecutionContext& Context) const
{
UStateTreeConditionBlueprintBase* Condition = Context.GetInstanceDataPtr<UStateTreeConditionBlueprintBase>(*this);
check(Condition);
return Condition->TestCondition(Context);
}