Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Animation Events Tightly Coupled to One Object?

Discussion in 'Animation' started by omatase, Jan 8, 2018.

  1. omatase

    omatase

    Joined:
    Jul 31, 2014
    Posts:
    159
    I have a quick question about animation events. I have an animation. On frame 13 I want to execute some code. I've tried doing this by adding an event to my animation but in order to fire the event Unity wants me to provide a Unity object on which to fire the event. I'm not sure what object to put in the "Object" field. Do I put my character in there? That is the object that contains the script that contains the code I want to execute when the animation event fires. If I do that though, now this animation is tightly coupled to that character, which feels weird, but I guess I won't be using the animation clip outside of that character anyway.

    Here is the relevant page in the Unity documentation.

    https://docs.unity3d.com/Manual/AnimationEventsOnImportedClips.html
     
  2. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,384
    I don't think the Obeject field is required.
     
  3. omatase

    omatase

    Joined:
    Jul 31, 2014
    Posts:
    159
    Interesting ...

    But how would it know what code to call when the event fires then?
     
  4. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,384
    function name
     
  5. omatase

    omatase

    Joined:
    Jul 31, 2014
    Posts:
    159
    OK, hmmmm, but how would it know which script to search for that function name?
     
  6. omatase

    omatase

    Joined:
    Jul 31, 2014
    Posts:
    159
    Wow, nevermind, it's, somehow working. I have a single script attached to my character and Unity was able to find my function. I'm not sure how it would if I had multiple scripts, but perhaps it looks through them all for it.

    Thanks for your help @LaneFox
     
    LukeDawn likes this.
  7. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,384
    It's sends the function call to every script on the animators gameobject.
     
    MentalGames, LukeDawn and omatase like this.