2021-09-28 13:33:17 -04:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "BrainComponent.h"
|
2023-01-25 02:42:36 -05:00
|
|
|
#include "GameplayTaskOwnerInterface.h"
|
2024-03-26 00:33:28 -04:00
|
|
|
#include "IStateTreeSchemaProvider.h"
|
2022-07-22 05:33:11 -04:00
|
|
|
#include "StateTreeReference.h"
|
2023-01-25 02:42:36 -05:00
|
|
|
#include "StateTreeInstanceData.h"
|
|
|
|
|
#include "UObject/Package.h"
|
2022-05-02 09:15:14 -04:00
|
|
|
#include "StateTreeComponent.generated.h"
|
2021-09-28 13:33:17 -04:00
|
|
|
|
2023-01-25 02:42:36 -05:00
|
|
|
enum class EStateTreeRunStatus : uint8;
|
|
|
|
|
struct FGameplayTag;
|
|
|
|
|
struct FStateTreeEvent;
|
|
|
|
|
struct FStateTreeExecutionContext;
|
|
|
|
|
|
2021-09-28 13:33:17 -04:00
|
|
|
class UStateTree;
|
|
|
|
|
|
2022-12-16 05:45:13 -05:00
|
|
|
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FStateTreeRunStatusChanged, EStateTreeRunStatus, StateTreeRunStatus);
|
|
|
|
|
|
2021-09-28 13:33:17 -04:00
|
|
|
UCLASS(ClassGroup = AI, HideCategories = (Activation, Collision), meta = (BlueprintSpawnableComponent))
|
2024-03-26 00:33:28 -04:00
|
|
|
class GAMEPLAYSTATETREEMODULE_API UStateTreeComponent : public UBrainComponent, public IGameplayTaskOwnerInterface, public IStateTreeSchemaProvider
|
2021-09-28 13:33:17 -04:00
|
|
|
{
|
|
|
|
|
GENERATED_BODY()
|
|
|
|
|
public:
|
2022-05-02 09:15:14 -04:00
|
|
|
UStateTreeComponent(const FObjectInitializer& ObjectInitializer = FObjectInitializer::Get());
|
2021-09-28 13:33:17 -04:00
|
|
|
|
|
|
|
|
// BEGIN UActorComponent overrides
|
|
|
|
|
virtual void InitializeComponent() override;
|
|
|
|
|
virtual void UninitializeComponent() override;
|
2022-08-29 14:47:43 -04:00
|
|
|
virtual void BeginPlay() override;
|
2023-03-17 09:41:07 -04:00
|
|
|
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
|
2021-09-28 13:33:17 -04:00
|
|
|
virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) override;
|
|
|
|
|
// END UActorComponent overrides
|
|
|
|
|
|
|
|
|
|
// BEGIN UBrainComponent overrides
|
|
|
|
|
virtual void StartLogic() override;
|
|
|
|
|
virtual void RestartLogic() override;
|
|
|
|
|
virtual void StopLogic(const FString& Reason) override;
|
|
|
|
|
virtual void Cleanup() override;
|
|
|
|
|
virtual void PauseLogic(const FString& Reason) override;
|
|
|
|
|
virtual EAILogicResuming::Type ResumeLogic(const FString& Reason) override;
|
|
|
|
|
virtual bool IsRunning() const override;
|
|
|
|
|
virtual bool IsPaused() const override;
|
|
|
|
|
// END UBrainComponent overrides
|
|
|
|
|
|
|
|
|
|
// BEGIN IGameplayTaskOwnerInterface
|
|
|
|
|
virtual UGameplayTasksComponent* GetGameplayTasksComponent(const UGameplayTask& Task) const override;
|
|
|
|
|
virtual AActor* GetGameplayTaskOwner(const UGameplayTask* Task) const override;
|
|
|
|
|
virtual AActor* GetGameplayTaskAvatar(const UGameplayTask* Task) const override;
|
|
|
|
|
virtual uint8 GetGameplayTaskDefaultPriority() const override;
|
|
|
|
|
virtual void OnGameplayTaskInitialized(UGameplayTask& Task) override;
|
|
|
|
|
// END IGameplayTaskOwnerInterface
|
|
|
|
|
|
2024-03-26 00:33:28 -04:00
|
|
|
// BEGIN IStateTreeSchemaProvider
|
|
|
|
|
TSubclassOf<UStateTreeSchema> GetSchema() const override;
|
|
|
|
|
// END
|
|
|
|
|
|
2023-03-13 10:18:23 -04:00
|
|
|
/**
|
|
|
|
|
* Sets whether the State Tree is started automatically on being play.
|
|
|
|
|
* This function sets the bStartLogicAutomatically property, and should be used mostly from constructions sscripts.
|
|
|
|
|
* If you wish to start the logic manually, call StartLogic().
|
|
|
|
|
*/
|
2022-12-15 15:55:44 -05:00
|
|
|
UFUNCTION(BlueprintCallable, Category = "Gameplay|StateTree")
|
|
|
|
|
void SetStartLogicAutomatically(const bool bInStartLogicAutomatically);
|
2024-03-25 19:58:58 -04:00
|
|
|
|
2022-09-01 09:06:53 -04:00
|
|
|
/** Sends event to the running StateTree. */
|
|
|
|
|
UFUNCTION(BlueprintCallable, Category = "Gameplay|StateTree")
|
|
|
|
|
void SendStateTreeEvent(const FStateTreeEvent& Event);
|
2022-11-01 15:11:19 -04:00
|
|
|
|
|
|
|
|
/** Sends event to the running StateTree. */
|
|
|
|
|
void SendStateTreeEvent(const FGameplayTag Tag, const FConstStructView Payload = FConstStructView(), const FName Origin = FName());
|
|
|
|
|
|
2022-12-16 05:45:13 -05:00
|
|
|
/** Returns the current run status of the StateTree. */
|
|
|
|
|
UFUNCTION(BlueprintPure, Category = "Gameplay|StateTree")
|
|
|
|
|
EStateTreeRunStatus GetStateTreeRunStatus() const;
|
|
|
|
|
|
|
|
|
|
/** Called when the run status of the StateTree has changed */
|
|
|
|
|
UPROPERTY(BlueprintAssignable, Category = "Gameplay|StateTree")
|
|
|
|
|
FStateTreeRunStatusChanged OnStateTreeRunStatusChanged;
|
|
|
|
|
|
2021-09-28 13:33:17 -04:00
|
|
|
#if WITH_GAMEPLAY_DEBUGGER
|
|
|
|
|
virtual FString GetDebugInfoString() const override;
|
|
|
|
|
#endif // WITH_GAMEPLAY_DEBUGGER
|
|
|
|
|
|
|
|
|
|
protected:
|
2021-11-24 04:26:12 -05:00
|
|
|
|
2022-07-22 05:33:11 -04:00
|
|
|
#if WITH_EDITORONLY_DATA
|
|
|
|
|
virtual void PostLoad() override;
|
|
|
|
|
#endif
|
2021-10-21 04:08:20 -04:00
|
|
|
|
2024-03-26 00:33:28 -04:00
|
|
|
virtual bool SetContextRequirements(FStateTreeExecutionContext& Context, bool bLogErrors = false);
|
2023-12-13 06:34:27 -05:00
|
|
|
|
2024-03-26 00:33:28 -04:00
|
|
|
virtual bool CollectExternalData(const FStateTreeExecutionContext& Context, const UStateTree* StateTree, TArrayView<const FStateTreeExternalDataDesc> Descs, TArrayView<FStateTreeDataView> OutDataViews) const;
|
2023-12-13 06:34:27 -05:00
|
|
|
|
2022-07-22 05:33:11 -04:00
|
|
|
#if WITH_EDITORONLY_DATA
|
|
|
|
|
UE_DEPRECATED(5.1, "This property has been deprecated. Use StateTreeReference instead.")
|
|
|
|
|
UPROPERTY()
|
2022-08-18 15:08:49 -04:00
|
|
|
TObjectPtr<UStateTree> StateTree_DEPRECATED;
|
2022-07-22 05:33:11 -04:00
|
|
|
#endif
|
|
|
|
|
|
2022-08-18 12:36:08 -04:00
|
|
|
UPROPERTY(EditAnywhere, Category = AI, meta=(Schema="/Script/GameplayStateTreeModule.StateTreeComponentSchema"))
|
2022-07-22 05:33:11 -04:00
|
|
|
FStateTreeReference StateTreeRef;
|
2021-09-28 13:33:17 -04:00
|
|
|
|
2022-12-15 15:55:44 -05:00
|
|
|
/** If true, the StateTree logic is started on begin play. Otherwise StartLogic() needs to be called. */
|
2022-08-29 14:47:43 -04:00
|
|
|
UPROPERTY(EditAnywhere, Category = AI)
|
|
|
|
|
bool bStartLogicAutomatically = true;
|
|
|
|
|
|
2022-03-23 08:06:00 -04:00
|
|
|
UPROPERTY(Transient)
|
2022-09-23 20:02:42 -04:00
|
|
|
FStateTreeInstanceData InstanceData;
|
2021-09-28 13:33:17 -04:00
|
|
|
|
|
|
|
|
/** if set, state tree execution is allowed */
|
|
|
|
|
uint8 bIsRunning : 1;
|
|
|
|
|
|
|
|
|
|
/** if set, execution requests will be postponed */
|
|
|
|
|
uint8 bIsPaused : 1;
|
|
|
|
|
};
|
2023-01-25 02:42:36 -05:00
|
|
|
|
|
|
|
|
#if UE_ENABLE_INCLUDE_ORDER_DEPRECATED_IN_5_2
|
|
|
|
|
#include "StateTreeExecutionContext.h"
|
|
|
|
|
#include "Tasks/AITask.h"
|
|
|
|
|
#endif
|