Skip to content
TheChatArchiveThe Chat Archive
Qwenqwen-max-2025-01-25· Alibaba (Qwen)Hugging Face LMArena Human Preference 140K

I'm using a UAbilityTask_WaitGameplayEvent() inside an ability which is triggered from a…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with DeepSeekdeepseek-r1-0528’s answer.
  1. User

    I'm using a UAbilityTask_WaitGameplayEvent() inside an ability which is triggered from a gameplay event notify in a montage but the task expects a FGameplayEventData as Payload when broadcasting the callback. Can I use some other task to react inside the ability on a anim notify which doesn't require a payload?

  2. Qwen Assistant

    Yes, you can use a different approach to handle animation notifies in your ability without requiring a FGameplayEventData payload. The UAbilityTask_WaitGameplayEvent is specifically designed to listen for gameplay events that carry FGameplayEventData, which may not be necessary for your use case if you're simply reacting to an animation notify.

    Instead of using UAbilityTask_WaitGameplayEvent, you can use one of the following alternatives:


    1. Use UAbilityTask_WaitGameplayTag

    If your animation notify broadcasts a gameplay tag (e.g., via IGameplayTagAssetInterface or a custom notify), you can use UAbilityTask_WaitGameplayTag. This task listens for the addition or removal of specific gameplay tags and does not require a payload.

    Example:

    UAbilityTask_WaitGameplayTag* Task = UAbilityTask_WaitGameplayTag::WaitForGameplayTag(this, FGameplayTag::RequestGameplayTag("AnimNotify.TagName"), true);
    Task->OnGameplayTagAdded.AddDynamic(this, &UYourAbilityClass::OnNotifyTriggered);
    Task->Activate();
    

    In this case, you would need to ensure that your animation notify adds or removes the specified gameplay tag.


    2. Use UAbilityTask_WaitDelay with Custom Logic

    If you don't want to deal with gameplay tags or payloads, you can directly trigger the ability logic when the animation notify fires. You can use a delegate or event system to notify the ability when the animation notify occurs.

    For example:

    • Create a custom delegate in your character or animation blueprint.
    • Bind the delegate to a function in your ability.
    • Trigger the delegate from the animation notify.

    Example:

    Character Class:

    DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnAnimNotifyTriggered);
    
    UCLASS()
    class YOURGAME_API AYourCharacter : public ACharacter
    {
        GENERATED_BODY()
    
    public:
        UPROPERTY(BlueprintAssignable)
        FOnAnimNotifyTriggered OnAnimNotifyTriggered;
    };
    

    Animation Notify:

    void UYourAnimNotify::Notify(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation)
    {
        if (AYourCharacter* Character = Cast<AYourCharacter>(MeshComp->GetOwner()))
        {
            Character->OnAnimNotifyTriggered.Broadcast();
        }
    }
    

    Ability Class:

    void UYourAbilityClass::ActivateAbility(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo, const FGameplayEventData* TriggerEventData)
    {
        Super::ActivateAbility(Handle, ActorInfo, ActivationInfo, TriggerEventData);
    
        if (AYourCharacter* Character = Cast<AYourCharacter>(ActorInfo->AvatarActor.Get()))
        {
            Character->OnAnimNotifyTriggered.AddDynamic(this, &UYourAbilityClass::OnNotifyTriggered);
        }
    }
    
    void UYourAbilityClass::OnNotifyTriggered()
    {
        // Handle the notify event here
    }
    

    This approach completely avoids the need for a payload and keeps the logic simple.


    3. Use UAbilityTask_PlayMontageAndWait

    If your goal is to react to specific points in the montage (e.g., when a notify fires), you can use UAbilityTask_PlayMontageAndWait. This task allows you to specify delegates for specific animation notifies.

    Example:

    UAbilityTask_PlayMontageAndWait* Task = UAbilityTask_PlayMontageAndWait::CreatePlayMontageAndWaitProxy(
        this, TEXT("TaskName"), MontageToPlay, 1.0f, FName("NotifyName"));
    Task->OnNotifyBegin.AddDynamic(this, &UYourAbilityClass::OnNotifyTriggered);
    Task->Activate();
    

    Here, OnNotifyBegin is triggered when the specified animation notify (NotifyName) is reached in the montage. This method is particularly useful if you're already playing a montage as part of the ability.


    4. Use a Custom Ability Task

    If none of the built-in tasks meet your needs, you can create a custom ability task that listens for animation notifies. This approach gives you full control over how the task reacts to notifies and whether it requires a payload.

    Steps:

    1. Create a new class inheriting from UAbilityTask.
    2. Override the Activate and OnDestroy methods.
    3. Register a delegate or bind to the animation notify event.
    4. Broadcast a custom event when the notify is triggered.

    Recommendation

    The best approach depends on your specific requirements:

    • If you're already using UAbilityTask_PlayMontageAndWait, extend its functionality to handle notifies.
    • If you want simplicity and flexibility, use a delegate-based system (Option 2).
    • If you prefer gameplay tags, use UAbilityTask_WaitGameplayTag.

    For most cases, Option 2 (Delegate-Based System) is the cleanest and most flexible solution, as it avoids unnecessary dependencies on payloads or gameplay tags.

    Let me know if you'd like further clarification or help implementing any of these approaches! 😊

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.