Search Unity

Animation Event Can't Find Function?

Discussion in 'Animation' started by fel3web, Aug 8, 2021.

  1. fel3web

    fel3web

    Joined:
    Mar 16, 2020
    Posts:
    19
    So i added a script called SpriteManager to my player and am trying to access the function
    public void ChangeSprite(string animation, int frame) from an event but it is not listed. how can i access it?

    sorry if i haven't provided all the information, just that i have no idea what could even be remotely helpful. please feel free to ask!
     
  2. Unrighteouss

    Unrighteouss

    Joined:
    Apr 24, 2018
    Posts:
    599
    Hey,

    Unfortunately, functions with multiple arguments don't seem to be supported with animation events. After some quick googling, there seems to be different workarounds, but I've never tried any of them.

    The simplest and probably least efficient workaround would be to use two different animation events, one for the string, and another for the int, and then pass those into the "ChangeSprite" function.
     
  3. fel3web

    fel3web

    Joined:
    Mar 16, 2020
    Posts:
    19
    damn unity sometimes amirite.
    well at least now i know what the problem is!

    thanks! i appreciate it!
    edit in case anyone finds this thread: since i have a short list (7) of valid string inputs, i'm choosing to work around this by adding a seperate function for each of my animations, and passing in the frame parameter where necessary.
     
    Last edited: Aug 10, 2021
    Unrighteouss likes this.