From d07579eb589b4a0218dd900f65006ecd456e140d Mon Sep 17 00:00:00 2001 From: Thibaut Spreux Date: Wed, 28 May 2025 11:29:41 +0200 Subject: [PATCH 1/4] add animnotify class --- ...playCueLooping_WithLineTraceParameters.cpp | 44 +++++++++++++++++++ ...meplayCueLooping_WithLineTraceParameters.h | 35 +++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 Source/GameBaseFramework/Private/Animation/GBFAnimNotify_GameplayCueLooping_WithLineTraceParameters.cpp create mode 100644 Source/GameBaseFramework/Public/Animation/GBFAnimNotify_GameplayCueLooping_WithLineTraceParameters.h diff --git a/Source/GameBaseFramework/Private/Animation/GBFAnimNotify_GameplayCueLooping_WithLineTraceParameters.cpp b/Source/GameBaseFramework/Private/Animation/GBFAnimNotify_GameplayCueLooping_WithLineTraceParameters.cpp new file mode 100644 index 00000000..c7f46734 --- /dev/null +++ b/Source/GameBaseFramework/Private/Animation/GBFAnimNotify_GameplayCueLooping_WithLineTraceParameters.cpp @@ -0,0 +1,44 @@ +#include "Animation/GBFAnimNotify_GameplayCueLooping_WithLineTraceParameters.h" + +#include +#include + +void UGBFAnimNotify_GameplayCueLooping_WithLineTraceParameters::NotifyBegin( USkeletalMeshComponent * mesh_component, UAnimSequenceBase * animation, float total_duration, const FAnimNotifyEventReference & event_reference ) +{ + auto * owning_actor = mesh_component->GetAttachmentRootActor(); + + if ( owning_actor != nullptr && GameplayCueTag.GetTagName() != NAME_None ) + { + FCollisionQueryParams collision_params; + collision_params.bReturnPhysicalMaterial = bReturnPhysicalMaterial; + + if ( bIgnoreSelfActor ) + { + collision_params.AddIgnoredActor( owning_actor ); + } + + auto start_location = owning_actor->GetActorLocation(); + auto end_location = owning_actor->GetActorLocation() + LineTraceVector; + + FHitResult hit_result; + owning_actor->GetWorld()->LineTraceSingleByChannel( hit_result, start_location, end_location, LineTraceChannel, collision_params ); + + auto gameplaycue_parameters = UGameplayCueFunctionLibrary::MakeGameplayCueParametersFromHitResult( hit_result ); + gameplaycue_parameters.TargetAttachComponent = mesh_component; + + UGameplayCueFunctionLibrary::AddGameplayCueOnActor( owning_actor, GameplayCueTag, gameplaycue_parameters ); + } +} + +void UGBFAnimNotify_GameplayCueLooping_WithLineTraceParameters::NotifyEnd( USkeletalMeshComponent * mesh_component, UAnimSequenceBase * animation, const FAnimNotifyEventReference & event_reference ) +{ + Super::NotifyEnd( mesh_component, animation, event_reference ); + + auto * owning_actor = mesh_component->GetAttachmentRootActor(); + if ( owning_actor != nullptr && GameplayCueTag.GetTagName() != NAME_None ) + { + FGameplayCueParameters gameplay_cue_parameters; + gameplay_cue_parameters.TargetAttachComponent = mesh_component; + UGameplayCueFunctionLibrary::RemoveGameplayCueOnActor( owning_actor, GameplayCueTag, gameplay_cue_parameters ); + } +} \ No newline at end of file diff --git a/Source/GameBaseFramework/Public/Animation/GBFAnimNotify_GameplayCueLooping_WithLineTraceParameters.h b/Source/GameBaseFramework/Public/Animation/GBFAnimNotify_GameplayCueLooping_WithLineTraceParameters.h new file mode 100644 index 00000000..d13f6864 --- /dev/null +++ b/Source/GameBaseFramework/Public/Animation/GBFAnimNotify_GameplayCueLooping_WithLineTraceParameters.h @@ -0,0 +1,35 @@ +#pragma once + +#include +#include + +#include "GBFAnimNotify_GameplayCueLooping_WithLineTraceParameters.generated.h" + +UCLASS( EditInlineNew, const, HideCategories = object, CollapseCategories, meta = ( DisplayName = "GBFGameplayCue (Looping) with line trace" ) ) +class GAMEBASEFRAMEWORK_API UGBFAnimNotify_GameplayCueLooping_WithLineTraceParameters final : public UAnimNotifyState +{ + GENERATED_BODY() + +public: + UGBFAnimNotify_GameplayCueLooping_WithLineTraceParameters() = default; + + void NotifyBegin( USkeletalMeshComponent * mesh_component, UAnimSequenceBase * animation, float total_duration, const FAnimNotifyEventReference & event_reference ) override; + void NotifyEnd( USkeletalMeshComponent * mesh_component, UAnimSequenceBase * animation, const FAnimNotifyEventReference & event_reference ) override; + +private: + UPROPERTY( EditAnywhere, Category = "GameplayCue", meta = ( Categories = "GameplayCue", AllowPrivateAccess ) ) + FGameplayTag GameplayCueTag; + + /* Starting from mesh_component's owning actor location */ + UPROPERTY( EditAnywhere, Category = "Parameters", meta = ( Categories = "Parameters", AllowPrivateAccess ) ) + FVector LineTraceVector; + + UPROPERTY( EditAnywhere, Category = "Parameters", meta = ( Categories = "Parameters", AllowPrivateAccess ) ) + uint8 bIgnoreSelfActor : 1; + + UPROPERTY( EditAnywhere, Category = "Parameters", meta = ( Categories = "Parameters", AllowPrivateAccess ) ) + uint8 bReturnPhysicalMaterial : 1; + + UPROPERTY( EditAnywhere, Category = "Parameters", meta = ( Categories = "Parameters", AllowPrivateAccess ) ) + TEnumAsByte< ECollisionChannel > LineTraceChannel; +}; From 125d4096d3fb8ae3b8e472a04c1a6b8cf24f6e66 Mon Sep 17 00:00:00 2001 From: Thibaut Spreux Date: Wed, 28 May 2025 15:42:39 +0200 Subject: [PATCH 2/4] add location management --- ...fy_GameplayCueLooping_WithLineTraceParameters.cpp | 12 +++++++++--- ...tify_GameplayCueLooping_WithLineTraceParameters.h | 3 +++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Source/GameBaseFramework/Private/Animation/GBFAnimNotify_GameplayCueLooping_WithLineTraceParameters.cpp b/Source/GameBaseFramework/Private/Animation/GBFAnimNotify_GameplayCueLooping_WithLineTraceParameters.cpp index c7f46734..9b03eea0 100644 --- a/Source/GameBaseFramework/Private/Animation/GBFAnimNotify_GameplayCueLooping_WithLineTraceParameters.cpp +++ b/Source/GameBaseFramework/Private/Animation/GBFAnimNotify_GameplayCueLooping_WithLineTraceParameters.cpp @@ -23,10 +23,16 @@ void UGBFAnimNotify_GameplayCueLooping_WithLineTraceParameters::NotifyBegin( USk FHitResult hit_result; owning_actor->GetWorld()->LineTraceSingleByChannel( hit_result, start_location, end_location, LineTraceChannel, collision_params ); - auto gameplaycue_parameters = UGameplayCueFunctionLibrary::MakeGameplayCueParametersFromHitResult( hit_result ); - gameplaycue_parameters.TargetAttachComponent = mesh_component; + auto gameplay_cue_parameters = UGameplayCueFunctionLibrary::MakeGameplayCueParametersFromHitResult( hit_result ); + gameplay_cue_parameters.TargetAttachComponent = mesh_component; + + if ( !bUseHitPointLocationForCue ) + { + gameplay_cue_parameters.Location = FVector3d::Zero(); + gameplay_cue_parameters.Normal = FVector3d::Zero(); + } - UGameplayCueFunctionLibrary::AddGameplayCueOnActor( owning_actor, GameplayCueTag, gameplaycue_parameters ); + UGameplayCueFunctionLibrary::AddGameplayCueOnActor( owning_actor, GameplayCueTag, gameplay_cue_parameters ); } } diff --git a/Source/GameBaseFramework/Public/Animation/GBFAnimNotify_GameplayCueLooping_WithLineTraceParameters.h b/Source/GameBaseFramework/Public/Animation/GBFAnimNotify_GameplayCueLooping_WithLineTraceParameters.h index d13f6864..2ae1531f 100644 --- a/Source/GameBaseFramework/Public/Animation/GBFAnimNotify_GameplayCueLooping_WithLineTraceParameters.h +++ b/Source/GameBaseFramework/Public/Animation/GBFAnimNotify_GameplayCueLooping_WithLineTraceParameters.h @@ -32,4 +32,7 @@ class GAMEBASEFRAMEWORK_API UGBFAnimNotify_GameplayCueLooping_WithLineTraceParam UPROPERTY( EditAnywhere, Category = "Parameters", meta = ( Categories = "Parameters", AllowPrivateAccess ) ) TEnumAsByte< ECollisionChannel > LineTraceChannel; + + UPROPERTY( EditAnywhere, Category = "Parameters", meta = ( Categories = "Parameters", AllowPrivateAccess ) ) + uint8 bUseHitPointLocationForCue : 1; }; From e33ea8d8ea0d607fa85e6b94fa0bfbba9327f222 Mon Sep 17 00:00:00 2001 From: Thibaut Spreux Date: Wed, 28 May 2025 16:30:59 +0200 Subject: [PATCH 3/4] clean class --- .../GBFAnimNotify_GameplayCueLooping.cpp | 36 +++++++++++-- ...playCueLooping_WithLineTraceParameters.cpp | 50 ------------------- .../GBFAnimNotify_GameplayCueLooping.h | 20 ++++++-- ...meplayCueLooping_WithLineTraceParameters.h | 38 -------------- 4 files changed, 49 insertions(+), 95 deletions(-) delete mode 100644 Source/GameBaseFramework/Private/Animation/GBFAnimNotify_GameplayCueLooping_WithLineTraceParameters.cpp delete mode 100644 Source/GameBaseFramework/Public/Animation/GBFAnimNotify_GameplayCueLooping_WithLineTraceParameters.h diff --git a/Source/GameBaseFramework/Private/Animation/GBFAnimNotify_GameplayCueLooping.cpp b/Source/GameBaseFramework/Private/Animation/GBFAnimNotify_GameplayCueLooping.cpp index 24d78d3d..f0583539 100644 --- a/Source/GameBaseFramework/Private/Animation/GBFAnimNotify_GameplayCueLooping.cpp +++ b/Source/GameBaseFramework/Private/Animation/GBFAnimNotify_GameplayCueLooping.cpp @@ -9,8 +9,35 @@ void UGBFAnimNotify_GameplayCueLooping::NotifyBegin( USkeletalMeshComponent * me if ( owning_actor != nullptr && GameplayCueTag.GetTagName() != NAME_None ) { - Parameters.TargetAttachComponent = mesh_component; - UGameplayCueFunctionLibrary::AddGameplayCueOnActor( owning_actor, GameplayCueTag, Parameters ); + FGameplayCueParameters gameplay_cue_parameters; + + if ( bUseLineTraceToFeelParameters ) + { + FHitResult hit_result; + + const auto trace_start_location = owning_actor->GetActorLocation(); + const auto trace_end_location = owning_actor->GetActorLocation() + LineTraceVector; + + FCollisionQueryParams collision_params; + collision_params.bReturnPhysicalMaterial = bGatherPhysicalMaterial; + collision_params.AddIgnoredActor( owning_actor ); + + owning_actor->GetWorld()->LineTraceSingleByChannel( hit_result, trace_start_location, trace_end_location, TraceCollisionChannel, collision_params ); + + if ( bGatherPhysicalMaterial ) + { + gameplay_cue_parameters.PhysicalMaterial = hit_result.PhysMaterial; + } + + if ( bGatherTraceHitPointLocation ) + { + gameplay_cue_parameters.Location = hit_result.Location; + gameplay_cue_parameters.Normal = hit_result.Normal; + } + } + + gameplay_cue_parameters.TargetAttachComponent = mesh_component; + UGameplayCueFunctionLibrary::AddGameplayCueOnActor( owning_actor, GameplayCueTag, gameplay_cue_parameters ); } } @@ -22,7 +49,8 @@ void UGBFAnimNotify_GameplayCueLooping::NotifyEnd( USkeletalMeshComponent * mesh if ( owning_actor != nullptr && GameplayCueTag.GetTagName() != NAME_None ) { - Parameters.TargetAttachComponent = mesh_component; - UGameplayCueFunctionLibrary::RemoveGameplayCueOnActor( owning_actor, GameplayCueTag, Parameters ); + FGameplayCueParameters gameplay_cue_parameters; + gameplay_cue_parameters.TargetAttachComponent = mesh_component; + UGameplayCueFunctionLibrary::RemoveGameplayCueOnActor( owning_actor, GameplayCueTag, gameplay_cue_parameters ); } } \ No newline at end of file diff --git a/Source/GameBaseFramework/Private/Animation/GBFAnimNotify_GameplayCueLooping_WithLineTraceParameters.cpp b/Source/GameBaseFramework/Private/Animation/GBFAnimNotify_GameplayCueLooping_WithLineTraceParameters.cpp deleted file mode 100644 index 9b03eea0..00000000 --- a/Source/GameBaseFramework/Private/Animation/GBFAnimNotify_GameplayCueLooping_WithLineTraceParameters.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include "Animation/GBFAnimNotify_GameplayCueLooping_WithLineTraceParameters.h" - -#include -#include - -void UGBFAnimNotify_GameplayCueLooping_WithLineTraceParameters::NotifyBegin( USkeletalMeshComponent * mesh_component, UAnimSequenceBase * animation, float total_duration, const FAnimNotifyEventReference & event_reference ) -{ - auto * owning_actor = mesh_component->GetAttachmentRootActor(); - - if ( owning_actor != nullptr && GameplayCueTag.GetTagName() != NAME_None ) - { - FCollisionQueryParams collision_params; - collision_params.bReturnPhysicalMaterial = bReturnPhysicalMaterial; - - if ( bIgnoreSelfActor ) - { - collision_params.AddIgnoredActor( owning_actor ); - } - - auto start_location = owning_actor->GetActorLocation(); - auto end_location = owning_actor->GetActorLocation() + LineTraceVector; - - FHitResult hit_result; - owning_actor->GetWorld()->LineTraceSingleByChannel( hit_result, start_location, end_location, LineTraceChannel, collision_params ); - - auto gameplay_cue_parameters = UGameplayCueFunctionLibrary::MakeGameplayCueParametersFromHitResult( hit_result ); - gameplay_cue_parameters.TargetAttachComponent = mesh_component; - - if ( !bUseHitPointLocationForCue ) - { - gameplay_cue_parameters.Location = FVector3d::Zero(); - gameplay_cue_parameters.Normal = FVector3d::Zero(); - } - - UGameplayCueFunctionLibrary::AddGameplayCueOnActor( owning_actor, GameplayCueTag, gameplay_cue_parameters ); - } -} - -void UGBFAnimNotify_GameplayCueLooping_WithLineTraceParameters::NotifyEnd( USkeletalMeshComponent * mesh_component, UAnimSequenceBase * animation, const FAnimNotifyEventReference & event_reference ) -{ - Super::NotifyEnd( mesh_component, animation, event_reference ); - - auto * owning_actor = mesh_component->GetAttachmentRootActor(); - if ( owning_actor != nullptr && GameplayCueTag.GetTagName() != NAME_None ) - { - FGameplayCueParameters gameplay_cue_parameters; - gameplay_cue_parameters.TargetAttachComponent = mesh_component; - UGameplayCueFunctionLibrary::RemoveGameplayCueOnActor( owning_actor, GameplayCueTag, gameplay_cue_parameters ); - } -} \ No newline at end of file diff --git a/Source/GameBaseFramework/Public/Animation/GBFAnimNotify_GameplayCueLooping.h b/Source/GameBaseFramework/Public/Animation/GBFAnimNotify_GameplayCueLooping.h index b564a802..0a04ead0 100644 --- a/Source/GameBaseFramework/Public/Animation/GBFAnimNotify_GameplayCueLooping.h +++ b/Source/GameBaseFramework/Public/Animation/GBFAnimNotify_GameplayCueLooping.h @@ -2,7 +2,6 @@ #include #include -#include #include "GBFAnimNotify_GameplayCueLooping.generated.h" @@ -21,6 +20,21 @@ class GAMEBASEFRAMEWORK_API UGBFAnimNotify_GameplayCueLooping final : public UAn UPROPERTY( EditAnywhere, Category = "GameplayCue", meta = ( Categories = "GameplayCue", AllowPrivateAccess ) ) FGameplayTag GameplayCueTag; - UPROPERTY( EditAnywhere, Category = "GameplayCue", meta = ( Categories = "GameplayCue", AllowPrivateAccess ) ) - FGameplayCueParameters Parameters; + UPROPERTY( EditAnywhere, Category = "Parameters", meta = ( AllowPrivateAccess ) ) + uint8 bUseLineTraceToFeelParameters : 1; + + /* Line trace will start at actor location */ + UPROPERTY( EditAnywhere, Category = "Parameters", meta = ( AllowPrivateAccess, EditCondition = "bUseLineTraceToFeelParameters" ) ) + FVector LineTraceVector; + + UPROPERTY( EditAnywhere, Category = "Parameters", meta = ( AllowPrivateAccess, EditCondition = "bUseLineTraceToFeelParameters" ) ) + TEnumAsByte< ECollisionChannel > TraceCollisionChannel; + + /* keep line trace hit point physical material, usefull for gameplay cue's surfaces spawn conditions */ + UPROPERTY( EditAnywhere, Category = "Parameters", meta = ( AllowPrivateAccess, EditCondition = "bUseLineTraceToFeelParameters" ) ) + uint8 bGatherPhysicalMaterial : 1; + + /* will override attachment gameplay cue position*/ + UPROPERTY( EditAnywhere, Category = "Parameters", meta = ( AllowPrivateAccess, EditCondition = "bUseLineTraceToFeelParameters" ) ) + uint8 bGatherTraceHitPointLocation : 1; }; diff --git a/Source/GameBaseFramework/Public/Animation/GBFAnimNotify_GameplayCueLooping_WithLineTraceParameters.h b/Source/GameBaseFramework/Public/Animation/GBFAnimNotify_GameplayCueLooping_WithLineTraceParameters.h deleted file mode 100644 index 2ae1531f..00000000 --- a/Source/GameBaseFramework/Public/Animation/GBFAnimNotify_GameplayCueLooping_WithLineTraceParameters.h +++ /dev/null @@ -1,38 +0,0 @@ -#pragma once - -#include -#include - -#include "GBFAnimNotify_GameplayCueLooping_WithLineTraceParameters.generated.h" - -UCLASS( EditInlineNew, const, HideCategories = object, CollapseCategories, meta = ( DisplayName = "GBFGameplayCue (Looping) with line trace" ) ) -class GAMEBASEFRAMEWORK_API UGBFAnimNotify_GameplayCueLooping_WithLineTraceParameters final : public UAnimNotifyState -{ - GENERATED_BODY() - -public: - UGBFAnimNotify_GameplayCueLooping_WithLineTraceParameters() = default; - - void NotifyBegin( USkeletalMeshComponent * mesh_component, UAnimSequenceBase * animation, float total_duration, const FAnimNotifyEventReference & event_reference ) override; - void NotifyEnd( USkeletalMeshComponent * mesh_component, UAnimSequenceBase * animation, const FAnimNotifyEventReference & event_reference ) override; - -private: - UPROPERTY( EditAnywhere, Category = "GameplayCue", meta = ( Categories = "GameplayCue", AllowPrivateAccess ) ) - FGameplayTag GameplayCueTag; - - /* Starting from mesh_component's owning actor location */ - UPROPERTY( EditAnywhere, Category = "Parameters", meta = ( Categories = "Parameters", AllowPrivateAccess ) ) - FVector LineTraceVector; - - UPROPERTY( EditAnywhere, Category = "Parameters", meta = ( Categories = "Parameters", AllowPrivateAccess ) ) - uint8 bIgnoreSelfActor : 1; - - UPROPERTY( EditAnywhere, Category = "Parameters", meta = ( Categories = "Parameters", AllowPrivateAccess ) ) - uint8 bReturnPhysicalMaterial : 1; - - UPROPERTY( EditAnywhere, Category = "Parameters", meta = ( Categories = "Parameters", AllowPrivateAccess ) ) - TEnumAsByte< ECollisionChannel > LineTraceChannel; - - UPROPERTY( EditAnywhere, Category = "Parameters", meta = ( Categories = "Parameters", AllowPrivateAccess ) ) - uint8 bUseHitPointLocationForCue : 1; -}; From dc83098511e9bcba05c49b7851aa584633e6ed64 Mon Sep 17 00:00:00 2001 From: Thibaut Spreux Date: Wed, 28 May 2025 21:55:10 +0200 Subject: [PATCH 4/4] review --- .../Animation/GBFAnimNotify_GameplayCueLooping.cpp | 2 +- .../Animation/GBFAnimNotify_GameplayCueLooping.h | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/GameBaseFramework/Private/Animation/GBFAnimNotify_GameplayCueLooping.cpp b/Source/GameBaseFramework/Private/Animation/GBFAnimNotify_GameplayCueLooping.cpp index f0583539..bc6af840 100644 --- a/Source/GameBaseFramework/Private/Animation/GBFAnimNotify_GameplayCueLooping.cpp +++ b/Source/GameBaseFramework/Private/Animation/GBFAnimNotify_GameplayCueLooping.cpp @@ -11,7 +11,7 @@ void UGBFAnimNotify_GameplayCueLooping::NotifyBegin( USkeletalMeshComponent * me { FGameplayCueParameters gameplay_cue_parameters; - if ( bUseLineTraceToFeelParameters ) + if ( bUseLineTraceToFillParameters ) { FHitResult hit_result; diff --git a/Source/GameBaseFramework/Public/Animation/GBFAnimNotify_GameplayCueLooping.h b/Source/GameBaseFramework/Public/Animation/GBFAnimNotify_GameplayCueLooping.h index 0a04ead0..206a6b15 100644 --- a/Source/GameBaseFramework/Public/Animation/GBFAnimNotify_GameplayCueLooping.h +++ b/Source/GameBaseFramework/Public/Animation/GBFAnimNotify_GameplayCueLooping.h @@ -21,20 +21,20 @@ class GAMEBASEFRAMEWORK_API UGBFAnimNotify_GameplayCueLooping final : public UAn FGameplayTag GameplayCueTag; UPROPERTY( EditAnywhere, Category = "Parameters", meta = ( AllowPrivateAccess ) ) - uint8 bUseLineTraceToFeelParameters : 1; + bool bUseLineTraceToFillParameters = false; /* Line trace will start at actor location */ - UPROPERTY( EditAnywhere, Category = "Parameters", meta = ( AllowPrivateAccess, EditCondition = "bUseLineTraceToFeelParameters" ) ) + UPROPERTY( EditAnywhere, Category = "Parameters", meta = ( AllowPrivateAccess, EditCondition = "bUseLineTraceToFillParameters" ) ) FVector LineTraceVector; - UPROPERTY( EditAnywhere, Category = "Parameters", meta = ( AllowPrivateAccess, EditCondition = "bUseLineTraceToFeelParameters" ) ) + UPROPERTY( EditAnywhere, Category = "Parameters", meta = ( AllowPrivateAccess, EditCondition = "bUseLineTraceToFillParameters" ) ) TEnumAsByte< ECollisionChannel > TraceCollisionChannel; /* keep line trace hit point physical material, usefull for gameplay cue's surfaces spawn conditions */ - UPROPERTY( EditAnywhere, Category = "Parameters", meta = ( AllowPrivateAccess, EditCondition = "bUseLineTraceToFeelParameters" ) ) + UPROPERTY( EditAnywhere, Category = "Parameters", meta = ( AllowPrivateAccess, EditCondition = "bUseLineTraceToFillParameters" ) ) uint8 bGatherPhysicalMaterial : 1; /* will override attachment gameplay cue position*/ - UPROPERTY( EditAnywhere, Category = "Parameters", meta = ( AllowPrivateAccess, EditCondition = "bUseLineTraceToFeelParameters" ) ) + UPROPERTY( EditAnywhere, Category = "Parameters", meta = ( AllowPrivateAccess, EditCondition = "bUseLineTraceToFillParameters" ) ) uint8 bGatherTraceHitPointLocation : 1; };