Yes, you can use UAbilityTask_WaitNotify instead, which is specifically designed to handle animation notifies without requiring a payload. This task reacts directly to anim notifies in montages and doesn't involve gameplay events or payloads. Here's how to implement it:
1. Create the Task in Your Ability
UAbilityTask_WaitNotify* WaitNotifyTask = UAbilityTask_WaitNotify::WaitNotify(
this, // Ability reference
NotifyName, // Name of the anim notify to wait for
nullptr, // Optional external target (usually nullptr)
true // Trigger once (or false for multiple triggers)
);
2. Bind the Callback
WaitNotifyTask->OnNotify.AddDynamic(this, &UYourAbility::OnAnimNotifyReceived);
WaitNotifyTask->ReadyForActivation();
3. Handle the Notify
void UYourAbility::OnAnimNotifyReceived()
{
// React to the anim notify here (e.g., trigger effects, sounds, etc.)
UE_LOG(LogTemp, Log, TEXT("Anim notify received!"));
}
Key Advantages:
- No Payload Required: Works with standard
AnimNotify (not AnimNotify_GameplayEvent).
- Direct Integration: Binds to the montage playing via
UAbilityTask_PlayMontageAndWait.
- Simpler Workflow: Avoids gameplay events/tags entirely.
Setup in Animation Notify:
-
In your animation montage, use a standard AnimNotify (not GameplayEvent-based).
- Assign a unique
Notify Name (e.g., "MyInteractionNotify").
-
Reference the same NotifyName in your task:
FName NotifyName = TEXT("MyInteractionNotify");
Full Workflow:
void UYourAbility::ActivateAbility(const FGameplayAbilitySpecHandle Handle, ...)
{
// Play the montage
UAbilityTask_PlayMontageAndWait* PlayMontageTask = UAbilityTask_PlayMontageAndWait::CreatePlayMontageAndWaitProxy(...);
// Wait for the anim notify
UAbilityTask_WaitNotify* WaitNotifyTask = UAbilityTask_WaitNotify::WaitNotify(
this,
TEXT("MyInteractionNotify"), // Must match the notify name in the montage
nullptr,
true
);
WaitNotifyTask->OnNotify.AddDynamic(this, &UYourAbility::OnInteractionNotify);
WaitNotifyTask->ReadyForActivation();
}
void UYourAbility::OnInteractionNotify()
{
// Handle the interaction here (e.g., crouch, spawn effects, etc.)
}
If You Must Use GameplayEvent Notifies:
If you're tied to AnimNotify_GameplayEvent, broadcast an empty payload:
// In your AnimNotify_GameplayEvent:
FGameplayEventData EmptyPayload;
AbilitySystemComponent->HandleGameplayEvent(EventTag, &EmptyPayload); // No payload needed
But UAbilityTask_WaitNotify is cleaner for simple notify reactions. Use this unless you need gameplay event data.