Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Source/UHLStateTree/Private/Notifies/UHL_AN_SendStateTreeEvent.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) 2024 NextGenium


#include "Notifies/UHL_AN_SendStateTreeEvent.h"

#include "Components/StateTreeComponent.h"

void UUHL_AN_SendStateTreeEvent::Notify(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UAN_UHL_SendStateTreeEvent

USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation,
const FAnimNotifyEventReference& EventReference)
{
Super::Notify(MeshComp, Animation, EventReference);

if (!MeshComp) return;

AActor* TargetActor = MeshComp->GetOwner();
if (!TargetActor) return;

if (APawn* Pawn = Cast<APawn>(TargetActor))
{
AController* Controller = Pawn->GetController();
if (!Controller) return;
UStateTreeComponent* STComp = Controller->FindComponentByClass<UStateTreeComponent>();
if (STComp!= nullptr)
{
STComp->SendStateTreeEvent(EventTag, Payload);
}
}
}
27 changes: 27 additions & 0 deletions Source/UHLStateTree/Public/Notifies/UHL_AN_SendStateTreeEvent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2024 NextGenium

#pragma once

#include "CoreMinimal.h"
#include "Animation/AnimNotifies/AnimNotify.h"
#include "GameplayTagContainer.h"
#include "StructUtils/InstancedStruct.h"
#include "UHL_AN_SendStateTreeEvent.generated.h"

/**
*
*/
UCLASS(Blueprintable, Category="UnrealHelperLibrary")
class UHLSTATETREE_API UUHL_AN_SendStateTreeEvent : public UAnimNotify
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, Category="SendStateTreeEvent")
FGameplayTag EventTag = FGameplayTag::EmptyTag;

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "SendStateTreeEvent")
FInstancedStruct Payload;

protected:
virtual void Notify(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, const FAnimNotifyEventReference& EventReference) override;
};