RPG Ability Course-TriggerAnimationEffect

HI there,

in Section 52 of the course on Udemy Sam learns use the cancel with IAction etc. Everything is working quit well, the only problem I have is that I am not able to cancel the Trigger Animation Effect so even if i cancel the following blast by moving the Ability Animation. I tried to restet the trigger but it doesnt work. I m quit new to c# and unity especially animations so maybe there is just a simple solution but I dont get it right now:

using System;
using System.Collections;
using UnityEngine;

namespace RPG.Abilities.Effects
{
    [CreateAssetMenu(fileName = "Trigger Animation Effect", menuName = "Abilities/Effects/Trigger Animation", order = 0)]
    public class TriggerAnimationEffect : EffectStrategy
    {
        [SerializeField] string animatonTrigger;
        [SerializeField] bool abortIfCancelled = false;
        public override void StartEffect(AbilityData data, Action finished)
        {
            Animator animator = data.GetUser().GetComponent<Animator>();
            animator.SetTrigger(animatonTrigger);
            if (abortIfCancelled && data.IsCancelled())
            {
                animator.ResetTrigger(animatonTrigger);
            }
            finished();
        }
    }
}

TY for any help.

The problem is that if the data is cancelled, you should never actually get to the TriggerAnimationEffect. If you take a look in the Ability, when things return from the targeting strategy, we abort if the Data.isCancelled.

There is a simple solution with no need to worry about abortIfCancelled… this is a trick I do with all calls to SetTrigger:
I do this:

animator.ResetTrigger(animationTrigger);
animator.SetTrigger(animationTrigger);

This effectively guarantees that the trigger will always be “reset” before setting it and should always properly trigger the needed animation.

thanks again Brian :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms