Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Discussion How would you create an animation-event based skill system? My solution and opinions.

Discussion in 'Animation' started by Christian-Tucker, Aug 13, 2022.

  1. Christian-Tucker


    Aug 18, 2013
    Hey everyone, I've recently started working on a little weekend project which has an ability-based combat system and I wanted to integrate animation cancelling as a fundamental feature that could be used to bait other players into wasting spells.

    I've already Implemented a basic ability system that works with animation cancelling, however I'm struggling to determine the best way to work with animation events, as this is my first time.

    Currently, the way that I handle this is that I have a PlayerAnimationEventReceiver class which listens to OnAbilityAnimationEvent and passes that up to the player, since my player controller & animator are on different objects. Within the animation event I make use of intParameter to specify which index the event is, so the first event would be 0, then 1, then 2... and so on.

    My abilities are set up as ScriptableObjects which each have their own Execute(Player player, Vector3 target, int animationEventIndex) implementation.

    Currently, what I do is based on the spells implementation, I can create GFX, Spawn Projectiles, or Execute any other code that I want, based on the animationEventIndex.

    An example of this would be a simple Fireball, during animationEventIndex=1 I would spawn the particles on the player's hand, to make it look like he's conjuring a fireball, during animationEventIndex=2 I would lock the player's movement, and during animationEventIndex=3 I would unlock the player's movement and create the GameObject containing the actual Fireball, which has it's own logic for movement/collision/etc.

    I feel like while this system works, it can be improved upon, but since I'm new to the events, I don't know how to improve upon it. I'm trying to improve this system before I build too many abilities into my project, but I'm stumped.