From 93ca460c8a2dfef6e8baeac38a1defaa1116939b Mon Sep 17 00:00:00 2001 From: Kevin Poretti Date: Sun, 6 Aug 2023 14:49:57 -0400 Subject: [PATCH] Call init when state is created by state machine and pass it state context --- Source/UnrealFightingFramework/State/FFState.cpp | 13 +++---------- Source/UnrealFightingFramework/State/FFState.h | 8 +++----- .../State/FFStateMachineComponent.cpp | 1 + 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/Source/UnrealFightingFramework/State/FFState.cpp b/Source/UnrealFightingFramework/State/FFState.cpp index a41541e..d4129d1 100644 --- a/Source/UnrealFightingFramework/State/FFState.cpp +++ b/Source/UnrealFightingFramework/State/FFState.cpp @@ -10,9 +10,9 @@ // UE includes #include "Components/SkeletalMeshComponent.h" -void UFFState::Init() +void UFFState::Init(const FFFStateContext& InStateContext) { - OnInit(); + OnInit(InStateContext); } bool UFFState::CanTransition(const FFFStateContext& InStateContext) @@ -153,7 +153,7 @@ void UFFState::RegisterInputHandler(const FFFInputSequence& InRequiredSequence, } -void UFFState::OnInit_Implementation() +void UFFState::OnInit_Implementation(const FFFStateContext& InStateContext) { } @@ -164,13 +164,6 @@ bool UFFState::OnCanTransition_Implementation(const FFFStateContext& InStateCont } -void UFFState::PostInitProperties() -{ - UObject::PostInitProperties(); - - Init(); -} - UWorld* UFFState::GetWorld() const { UFFStateMachineComponent* SMC = Cast(GetOuter()); diff --git a/Source/UnrealFightingFramework/State/FFState.h b/Source/UnrealFightingFramework/State/FFState.h index 0669863..13e9c9f 100644 --- a/Source/UnrealFightingFramework/State/FFState.h +++ b/Source/UnrealFightingFramework/State/FFState.h @@ -76,7 +76,7 @@ public: * How long this state will be active before finishing if this state is not cancelled out of * by other means. */ - UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="UFF State Properties") + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category="UFF State Properties") int64 StateDuration; /** @@ -123,7 +123,7 @@ public: /** * Called when state is first created. */ - virtual void Init(); + virtual void Init(const FFFStateContext& InStateContext); /** * Returns true if Avatar's is in the correct stance AND @@ -189,7 +189,7 @@ public: const FFFInputSequence& InRequiredSequence, FFFInputEventDelegate InDelegate); UFUNCTION(BlueprintNativeEvent, Category="UFF|State|Events") - void OnInit(); + void OnInit(const FFFStateContext& InStateContext); /** * Blueprint hook for overriding the CanTransition logic @@ -232,8 +232,6 @@ public: void OnBlock(const FFFStateContext& InStateContext); // UObject interface - virtual void PostInitProperties() override; - virtual UWorld* GetWorld() const override; // End of UObject interface }; diff --git a/Source/UnrealFightingFramework/State/FFStateMachineComponent.cpp b/Source/UnrealFightingFramework/State/FFStateMachineComponent.cpp index 7649068..0b7c716 100644 --- a/Source/UnrealFightingFramework/State/FFStateMachineComponent.cpp +++ b/Source/UnrealFightingFramework/State/FFStateMachineComponent.cpp @@ -56,6 +56,7 @@ UFFState* UFFStateMachineComponent::AddState(TSubclassOf StateClassToA if(!FindStateWithName(TempState->Name)) { States.Add(TempState); + TempState->Init(GetCurrentStateContext()); return TempState; }