Files
UnrealEngineUWP/Engine/Plugins/Runtime/StateTree/Source/StateTreeModule/Private/Tasks/StateTreeDebugTextTask.cpp
mikko mononen 186e03b32e StateTree: Improved event handling
- Moved event queue to it's own struct
- Changed the SendEvent() API to accept struct view to prevent instanced struct copy in common cases
- Fixed event handling in case EnterState() fails.
- Added option for Tasks to disavble ticking, or to be ticked only when there are events
- Added option for Tasks handle when properties are copied
- Changed DebugText to use external Actor reference
- Changed DelayTask to use the new GetInstanceData which does not need type
- Added TStateTreeInstanceDataStructRef which can be used to access struct instance data in delegates

#rb Maxime.Mercier Luciano.Ferraro
#preflight 6360dd302b5338aceb2d0343

[CL 22888708 by mikko mononen in ue5-main branch]
2022-11-01 15:11:19 -04:00

64 lines
1.8 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "StateTreeDebugTextTask.h"
#include "StateTreeExecutionContext.h"
#include "StateTreeLinker.h"
#include "GameFramework/Actor.h"
#include "DrawDebugHelpers.h"
#include UE_INLINE_GENERATED_CPP_BY_NAME(StateTreeDebugTextTask)
EStateTreeRunStatus FStateTreeDebugTextTask::EnterState(FStateTreeExecutionContext& Context, const FStateTreeTransitionResult& Transition) const
{
if (!bEnabled)
{
return EStateTreeRunStatus::Succeeded;
}
const FInstanceDataType& InstanceData = Context.GetInstanceData(*this);
const UWorld* World = Context.GetWorld();
if (World == nullptr && InstanceData.ReferenceActor != nullptr)
{
World = InstanceData.ReferenceActor->GetWorld();
}
// Reference actor is not required (offset will be used as a global world location)
// but a valid world is required.
if (World == nullptr)
{
return EStateTreeRunStatus::Failed;
}
DrawDebugString(World, Offset, Text, InstanceData.ReferenceActor, TextColor, /*Duration*/-1, /*DrawShadows*/true, FontScale);
return EStateTreeRunStatus::Running;
}
void FStateTreeDebugTextTask::ExitState(FStateTreeExecutionContext& Context, const FStateTreeTransitionResult& Transition) const
{
if (!bEnabled)
{
return;
}
const FInstanceDataType& InstanceData = Context.GetInstanceData(*this);
const UWorld* World = Context.GetWorld();
if (World == nullptr && InstanceData.ReferenceActor != nullptr)
{
World = InstanceData.ReferenceActor->GetWorld();
}
// Reference actor is not required (offset was used as a global world location)
// but a valid world is required.
if (World == nullptr)
{
return;
}
// Drawing an empty text will remove the HUD DebugText entries associated to the target actor
DrawDebugString(World, Offset, "", InstanceData.ReferenceActor);
}