Search Unity

[RELEASED] Animator Events

Discussion in 'Assets and Asset Store' started by forestrf, Aug 27, 2020.

  1. forestrf

    forestrf

    Joined:
    Aug 28, 2010
    Posts:
    231
    Animator Events
    Asset Store | Discord


    Tired of string-based events tied to animations? So were we! With this asset, you will be able to associate events with animator states for a smoother workflow, with several additional goodies.

    With this asset you can easily set UnityEvents, give them a name and assign them to Animator States using a drop-down alongside the condition that must be met to execute them.

    Not only can you execute UnityEvents, you can also set parameters of the Animator to make a more complex Controller.

    Features
    Given a condition, trigger a UnityEvent or set a parameter to a specific value
    The possible conditions are On State Enter and On State Exit, both when the Transition Starts or when the Transition Ends, or you can set a Specific Normalize Time.

    This asset was created as a way to handle the character logic in the game Genokids So that hitboxes, visual effects and logic like jumping or disallowing being grounded is enabled, disabled or fired when needed given the animation state without needed to add code and in a easy way that is also quick to iterate on.

    Requirements
    Requires Unity 2018 or higher





    1.png
     
    Last edited: Jan 12, 2021
    Ultroman, jiraphatK and dizzymediainc like this.
  2. umutulutas

    umutulutas

    Joined:
    May 27, 2014
    Posts:
    1
    Can I specify frame number instead of Normalized time (seconds) for when the event will fire?
     
  3. forestrf

    forestrf

    Joined:
    Aug 28, 2010
    Posts:
    231
    No.

    TL;DR Tell me if you would be ok with frames as a "hint", an alternative way of seeing the normalized time, to make easier to author events, but knowing that normalized time is what's actually being used and that the frame number may not match once blend trees and animator overrides are introduced.


    I don't know right now how I could implement it because:

    - In the case of a state that has a single animation, I could check the animation framerate to derive from it the frame number while still working with normalized times, but if the animator uses an override, the overrided animation can have a different number of frames and so the normalized time won't match. That means using frames as an alternative way to show a normalized time is not possible and working with actual frame numbers is needed.

    - In the case of a blend tree, I don't even know right now how a frame would be handled there when it holds clips of different lengths and it's interpolating between them.

    - Lastly, because the animator (usually) plays using frame time and not a fixed one, frames won't fall exactly at the start of a frame, and probably some frames will be somewhat skipped even with a mostly constant framerate. In those cases, having an event on a specific frame.



    Given all of that I can't see a way to add support for inputing frames and having it work correctly.
    Unity supports events on clips at certain frames, and I suppose artists would prefer to work with frame numbers even if they are just normalized times interpreted as frames, but if that would make it easier to work with this asset and you think it's worth it, I could try adding the option to show time in frames as a guide, maybe even snapping the time slider to the frames.

    What do you think?
     
    Last edited: Oct 9, 2022
  4. ChrisBQ

    ChrisBQ

    Joined:
    Apr 14, 2022
    Posts:
    1
    We added an AnimatorOverrideController to one of our game characters, which was set up to use this but it errored in StatesUsingEvent inside the editor. Think its related to updating the usages count. As the override system is at runtime it kinda messes that up. Have made it handle a null case for now but any guidance would be appreciated.
     
  5. forestrf

    forestrf

    Joined:
    Aug 28, 2010
    Posts:
    231
    I think I found the bug you are talking about. I found the button "Where is it used? (shown in the Console)" wasn't working when the Animator was using an AnimatorOverrideController. I fixed it and will be available on the asset store in a couple of days. If you can't wait for the fix, please send me an email (with the asset store invoice number) to forestrf@gmail.com or join the discord server (https://discord.gg/WyxYWPCG7F).

    If that was not the bug you reported or something else happens, please consider sending me a small Unity project with the bug happening, or a more detailed explanation of it.