Search Unity

Animation Event show a lot of function but not the function i created

Discussion in 'Scripting' started by f2pallglory, Feb 17, 2019.

  1. f2pallglory

    f2pallglory

    Joined:
    Jan 11, 2019
    Posts:
    25
    Hello guys,

    i wanna add my method that i have on my script at Gamecontroller object, but when i add an event inside the animation it doesnt show the method i needed just a lot of function from unity itself, like this:

    Untitled.jpg

    i have tried to add the script to the gameobject where the animation is but still the same,
    what did i do wrong here?
    Thank you
     
  2. DeeJayVee

    DeeJayVee

    Joined:
    Jan 2, 2015
    Posts:
    121
    Is your new method public?
     
    f2pallglory likes this.
  3. f2pallglory

    f2pallglory

    Joined:
    Jan 11, 2019
    Posts:
    25
    yes, it is public already
     
  4. f2pallglory

    f2pallglory

    Joined:
    Jan 11, 2019
    Posts:
    25
    Okay was dumb of me, i attach the script to wrong gameobject .. turn out attaching it to the gameobject itself is working

    Thankyou
     
    GameLover90 likes this.
  5. GiorgioK

    GiorgioK

    Joined:
    Oct 20, 2021
    Posts:
    34
    I also had a similar problem. But it turned out that the function prototype must meet certain requirements. Help link: https://docs.unity3d.com/ScriptReference/AnimationEvent.html
    1. The method must be public.
    2. Animation events support method that take zero or one parameter. Two or three parameters you can't do !!!!
    3. The parameter can be a float, an int, a string, an object reference, or an AnimationEvent. For example, a parameter cannot be of type bool or byte !!!

    Why and why such strange restrictions are made is not clear...
    Probably religion does not allow to do it normally...
     
    sandex443 and superch like this.
  6. justrenis

    justrenis

    Joined:
    Apr 26, 2020
    Posts:
    1
    Very nice, i have to make another function just because AnimationEvent does not take a parameter as bool........