Animation Event won't show the function I need
Asked Answered
C

7

0

I’m trying to add a function to fire on a certain frame, but the function I need will not show up in the edit animation event window. How do I fix this?

Creditable answered 13/9, 2023 at 4:36 Comment(0)
D
0

animation event calls public methods of other components attached to gameObject playing the animation

so basically make component (monobehaviour class) AnimationEventListener and make public method like

public void EventHandlerMethod()
{
// the code you need
}

attach it to the gameObject in scene and it should appear in the dropdown menu of AnimationEvent keyframe

Dasi answered 6/6, 2023 at 2:36 Comment(2)

Ok, but the animation event window only shows functions from the parent gameobject. How do I make it show the functions of the child gameobjects?

Creditable

i'm not sure you can do that, but for sure you can call them from the parent component http://docs.unity3d.com/Documentation/ScriptReference/Component.GetComponentInChildren.html

Dasi
S
0

Check out this answer: Why don't animation events allow you to call functions that take a bool parameter? - Unity Answers

If you have a boolean parameter, it doesn’t show

Soutane answered 6/6, 2023 at 2:41 Comment(0)
F
0

Old question but I worked this out, if you select an animation clip in the Project explorer and try and edit an event’s properties it wont show a list of available functions.

However If you select an object in your scene graph with an Animator component then bring the Animation window and select your clip in the dropdown it will show a list of functions you can call. It makes sense because Unity won’t know which functions it can call just by editing the animation clip asset, it needs the context of the game object that’s playing it.

Floranceflore answered 19/7, 2023 at 6:38 Comment(1)

Thanks. This is one of those things that if you don't do often, even if you know it, you may forget. I'm really glad you posted your answer!

Whippersnapper
M
0

For anybody else who lands here, the animator can only call methods with a single parameter. If you have several parameters, it won’t appear on the list. You have to pass a parameter of type AnimationEvent . Here are more details: One parameter limit on animation event functions temporary? - Unity Answers

Microfilm answered 6/6, 2023 at 2:36 Comment(0)
H
0

but how can I fix the problem if I want to call a function that is in another game object that the animation clip is on, the function is public and I tried locking the inspector on the animation clip, then selecting the game object that has the function I want to call but still no result ! @Floranceflore

Haematoxylin answered 11/9, 2021 at 16:20 Comment(0)
K
0

Old question, but another issue that might cause this is attaching the script to a child of the object holding the animator, the script must be attached to the parent object for the function to show.

Kutenai answered 6/6, 2023 at 2:37 Comment(0)
S
0

I used a public function and put the script into the game object with the Animator component.

Speakeasy answered 13/9, 2023 at 2:54 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.