From c4e40037ed1a1d1be1181081c15b72e72d4708f5 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Thu, 25 Apr 2024 12:46:26 -0400 Subject: [PATCH] 53. Gameplay Effect Delegates --- .../GasaAbilitySystemComponent.cpp | 21 ++++++++++++++++++- .../GasaAbilitySystemComponent.h | 9 +++++++- .../Source/Gasa/Characters/GasaCharacter.cpp | 12 +++++------ 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/Project/Source/Gasa/AbilitySystem/GasaAbilitySystemComponent.cpp b/Project/Source/Gasa/AbilitySystem/GasaAbilitySystemComponent.cpp index d78257c..7b856b3 100644 --- a/Project/Source/Gasa/AbilitySystem/GasaAbilitySystemComponent.cpp +++ b/Project/Source/Gasa/AbilitySystem/GasaAbilitySystemComponent.cpp @@ -1 +1,20 @@ -#include "GasaAbilitySystemComponent.h" \ No newline at end of file +#include "GasaAbilitySystemComponent.h" + +#include "Engine/Engine.h" + +void UGasaAbilitySystemComp::OnAbilityActorInfoSet() +{ +} + +void UGasaAbilitySystemComp::EffectApplied(UAbilitySystemComponent* AbilitySystem, FGameplayEffectSpec const& Spec, + FActiveGameplayEffectHandle ActiveEffect) +{ + GEngine->AddOnScreenDebugMessage(1, 8.f, FColor::Yellow, FString("Effect applied")); +} + +void UGasaAbilitySystemComp::InitAbilityActorInfo(AActor* InOwnerActor, AActor* InAvatarActor) +{ + Super::InitAbilityActorInfo(InOwnerActor, InAvatarActor); + + OnGameplayEffectAppliedDelegateToSelf.AddUObject(this, & ThisClass::EffectApplied); +} diff --git a/Project/Source/Gasa/AbilitySystem/GasaAbilitySystemComponent.h b/Project/Source/Gasa/AbilitySystem/GasaAbilitySystemComponent.h index 8ec5d5e..10bb10f 100644 --- a/Project/Source/Gasa/AbilitySystem/GasaAbilitySystemComponent.h +++ b/Project/Source/Gasa/AbilitySystem/GasaAbilitySystemComponent.h @@ -6,10 +6,17 @@ #include "GasaAbilitySystemComponent.generated.h" - UCLASS(BlueprintType) class GASA_API UGasaAbilitySystemComp : public UAbilitySystemComponent { GENERATED_BODY() public: + // TODO(Ed): If hes only using this to bind the EffectApplied to a delegate, then just use the init override instead. + void OnAbilityActorInfoSet(); + + void EffectApplied(UAbilitySystemComponent* AbilitySystem, FGameplayEffectSpec const& Spec, FActiveGameplayEffectHandle ActiveEffect); + +#pragma region AbilitySystemComponent + void InitAbilityActorInfo(AActor* InOwnerActor, AActor* InAvatarActor) override; +#pragma endregion AbilitySystemComponent }; diff --git a/Project/Source/Gasa/Characters/GasaCharacter.cpp b/Project/Source/Gasa/Characters/GasaCharacter.cpp index 7eee235..05c1ef2 100644 --- a/Project/Source/Gasa/Characters/GasaCharacter.cpp +++ b/Project/Source/Gasa/Characters/GasaCharacter.cpp @@ -155,12 +155,11 @@ void AGasaCharacter::PossessedBy(AController* NewController) if (GetMesh() && IsReplicatingMovement() && (GetRemoteRole() == ROLE_AutonomousProxy && GetNetConnection() != nullptr)) GetMesh()->bOnlyAllowAutonomousTickPose = true; } - + +#if 0 if (bAutoAbilitySystem) - { - // TODO(Ed): Do we need to do this for enemies? AbilitySystem->InitAbilityActorInfo(this, this); - } +#endif } void AGasaCharacter::SetPlayerDefaults() @@ -179,11 +178,10 @@ void AGasaCharacter::BeginPlay() { Super::BeginPlay(); + // TODO(Ed): Find out if this is the best spot todo this + // There is also OnPossessed, PostInitializeComponents, etc... if (bAutoAbilitySystem) - { - // TODO(Ed): Do we need to do this for enemies? AbilitySystem->InitAbilityActorInfo(this, this); - } } void AGasaCharacter::Tick(float DeltaSeconds)