Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Target a scriptable object with Animation Events (Request)

Discussion in 'Animation' started by kbabilinski, Jan 12, 2018.

  1. kbabilinski

    kbabilinski

    Joined:
    Jul 12, 2012
    Posts:
    19
    Currently Unity doesn't support targeting a scriptable object as the receiver for animation events. I posted an idea on the unity feedback page to encourage developing this feature.
    https://feedback.unity3d.com/suggestions/support-scriptable-object-architecture-in-animation-events

    Case Story
    Here is a simple use case, I have a demo walking animation that I'm using as part of the development cycle. I want the character to have footstep sounds. An artist on the team is experimenting with new animations, they decide to replace the animation with a new one.

    Problem 1:
    The events are deleted and the artist doesn't remember what was the string for the footstep animations, he has to refer to the monobehaviour script.
    Solution
    The animation event targeted a scriptable object. In the project folder we have a list of scriptable objects that are named corresponding to the event they catch. The artists looks for WalkingSFX and references the key value.

    Case Story Continued
    The designer decides to change the character model to match the new animation,

    Problem 2:
    The designer hits play and is greeted with a bunch of error messages, one for each event that is not caught. because he forgot to apply the monobehaviour scripts
    Solution
    The designer hits play and is greeted with a note from one of the developers "The scriptable object (name) caught the event but was not able to execute it because a reference game object has not been set"

    Scriptable objects are always present, the only reference that is required is to a gameobject that processes the event.

    Case Story Continued
    After some time, the designer finds out that the new animations are dense in keyframes, he begins editing the import settings on the animation.

    Problem 3:
    The animation events can easily be lost when editing the import settings, this will cause problems 1 and 2 to repeat
    Solution
    A scriptable object could have a description of the event, the key required, and the target model that it was created for.


    Let me know what you guys think, am I being dramatic? There's just something I don't like about having to rely on monobehaviors and import settings.
     
    AlejMC likes this.
  2. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,462
    The Object field is for passing an object as an argument, not as a target.

    I suppose what you're asking is for the ability to target an asset with the function and arguments already configured so that the designer doesn't have to put them in every time he reimports the animation?

    That seems probably too specific to me and they would still need to know what function on the asset to call so all it seems to do is redirect the issue. You could make extension methods on the Animator and call those, bypassing the need for a new component on the gameObject. That might be easier for you to standardize.
     
  3. kbabilinski

    kbabilinski

    Joined:
    Jul 12, 2012
    Posts:
    19
    I guess my understanding of animation events is limited. I didn't realize that the object field was for passing values.

    I guess I was thinking that unity was moving to a scriptable object system for a lot of it's functions, like image processing. Isn't the idea of scriptable objects as abilities, image effects, and AI to make it more reusable? Why couldn't they add something similar to animation events?


    Great suggestion on the extension method idea. I'll apply that to my current project. I'll post updates as I develop it.

     
  4. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,462
    They're basically interchangeable, customizeable assets (and instances, if you want) that you can drop into fields and gain a lot of re-usability from. For instance if you have say a configuration for how a gun fires but all guns basically have Fire(), baseDamage and baseSpeed and projectilePrefab... then you can put those on an SO and make a slot on your weapon to accept a FireConfig SO asset and pipe all the firing through that object reference. This would make configuring and designing how and what weapons fire just a matter of putting a different SO into the slot and immediately change the behavior of the weapon.

    This applies to many other things as well. You can use them for simple equality checks to see if it's the right ammoType, for example. There are a lot of possibilities and design patterns to take advantage of with ScriptableObjects.
     
    theANMATOR2b likes this.
  5. kbabilinski

    kbabilinski

    Joined:
    Jul 12, 2012
    Posts:
    19
    I guess I'm still not sure on why doesn't it make sense to support catching animation events in scriptable objects? You can create State Machine behaviors (they remain separate from the animations) but you can't create Animation State behaviors.
     
  6. AlejMC

    AlejMC

    Joined:
    Oct 15, 2013
    Posts:
    149
    Agreed.
    With the whole idea of using scriptable objects to aid game design architecture, it would be great indeed if animation events where as powerful as normal Unity Events.
    I'm going through the exact footstep situation and am being force to use a middle man script attached to the GameObject that contains the animation.
    - Animator calls a 'RaiseEvent' on each step
    - A script attached to the same GameObject gets this and calls the appropriate inspector binded ScriptableObject "event"