Stop ability on animation event?

revenz

New member
Hi, Is there a way to stop an ability on an animation event or when an animation has completed?

I've added a basic dodge roll ability, and just need to mark it as complete once the animation has completed. Currently using a coroutine in the AbilityStarted method, but this can be error-prone.

TIA
 
Are You created your ability as a new one by inheriting from Ability base class ?

If so u should be able to select "Wait for animation event to Complete" in the inspector, then u will have to set event in the Animation and that should work for you.
Probably You will need to write some lines of code. Basic stuff seems like that:
1624635322606.png

And then in the Inspector you Should be able to see animation event trigger. But first, make sure You understand how it works, because probalby You will have to implement some functions to make it working like u wish with animation event :)

1624635306546.png



You can also get the reference to ability and stop that manually (that should be more straight-forward, but less user-frendly for designers). Sample code below:

Code:
Ability rollBackAbility = characterLocomotion.GetAbility<RollBackAbility>();

if(rollBackAbility.CanStopAbility) rollBackAbility.StopAbility();


And u can call this function as an AnimationEvent. Should stop the ability for You ;)
 
Thanks guys, go it.

For anyone else:
  1. In my abilities Awake I added
    EventHandler.RegisterEvent(m_GameObject, "OnDodgeRollComplete", OnAnimationComplete);
  2. Added this method to my ability to stop it
    private void OnAnimationComplete() => StopAbility();
  3. Editting my roll animation and added an event
    Function: ExecuteEvent
    String: OnDodgeRollComplete
  4. In code where I init the dodge roll ability, I added
    DodgeAbilityEvent.WaitForAnimationEvent = true;

I don't have the opsive roll ability plugin. If it goes on sale during the summer sale I may pick it up, but really just wanted a dodge roll ability so didn't really need it, and it's good learning how to add this stuff. Because there are a few more custom abilities I'm trying to add as well.
 
Top