this is code, where Notify is used.
Notify:
h
#pragma once
#include "CoreMinimal.h"
#include "Animation/AnimNotifies/AnimNotify.h"
#include "ClipingAnimNotify.generated.h"
DECLARE_MULTICAST_DELEGATE_OneParam(FOnNotifiedSignature, USkeletalMeshComponent*)
UCLASS()
class MYPROJECT_API UClipingAnimNotify : public UAnimNotify
{
GENERATED_BODY()
public:
virtual void Notify(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation) override;
FOnNotifiedSignature OnNotified;
};
cpp
#include "Animations/ClipingAnimNotify.h"
void UClipingAnimNotify::Notify(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation)
{
OnNotified.Broadcast(MeshComp);
Super::Notify(MeshComp, Animation);
}
WeaponComponent:
h
UPROPERTY(EditDefaultsOnly, Category = "Weapon")
UAnimMontage* CurrentReloadAnimation = nullptr;
cpp
void UWeaponComponent::InitAnim()
{
if (!CurrentReloadAnimation) return;
const auto& NotifyEvents = CurrentReloadAnimation->Notifies;
for (const FAnimNotifyEvent& NotifyEvent : NotifyEvents)
{
if (auto ClipingFinishNotify = Cast<UClipingAnimNotify>(NotifyEvent.Notify))
{
ClipingFinishNotify->OnNotified.AddUObject(this, &UWeaponComponent::OnClipingFinished);
break;
}
}
}
void UWeaponComponent::OnClipingFinished(USkeletalMeshComponent* MeshComp)
{
ACharacter* Character = Cast<ACharacter>(GetOwner());
if (!Character || MeshComp != Character->GetMesh()) return;
IsClipingInProgress = false;
}