Legacy Documentation: Version 4.6.2
Language: English
Objects with Multiple Moving Parts
Animation Reference

Using Animation Events

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

The power of animation clips can be increased by using Animation Events, which allow you to call functions in the object’s script at specified points in the timeline.

The function called by an animation event can optionally take one parameter. The parameter can be a float, string, int, object reference or an AnimationEvent object. The AnimationEvent object has member variables that allow a float, string, integer and object reference to be passed into the function all at once, along with other information about the event that triggered the function call.

// This JavaScript function can be called by an Animation Event
function PrintFloat (theValue : float) {
    Debug.Log ("PrintFloat is called with a value of " + theValue);
}


You can add an animation event to a clip at the current playhead position by clicking the Event button or at any point in the animation by double-clicking the Event Line at the point where you want the event to be triggered. Once added, an event can be repositioned by dragging with the mouse. You can delete an event by selecting it and pressing Delete, or by right-clicking on it and selecting Delete Event from the contextual menu.

<span class="doc-keyword">Animation Events</span> are shown in the <span class="doc-menu">Event Line</span>. Add a new <span class="doc-keyword">Animation Event</span> by double-clicking the <span class="doc-menu">Event Line</span> or by using the <span class="doc-menu">Event button</span>.
Animation Events are shown in the Event Line. Add a new Animation Event by double-clicking the Event Line or by using the Event button.

When you add an event, a dialog box will appear to prompt you for the name of the function and the value of the parameter you want to pass to it.

The <span class="doc-keyword">Animation Event</span> popup dialog lets you specify which function to call with which parameter value.
The Animation Event popup dialog lets you specify which function to call with which parameter value.

The events added to a clip are shown as markers in the event line. Holding the mouse over a marker will show a tooltip with the function name and parameter value.

Holding the mouse cursor over an <span class="doc-menu">Animation Event marker</span> will show which function it calls as well as the parameter value.
Holding the mouse cursor over an Animation Event marker will show which function it calls as well as the parameter value.
Objects with Multiple Moving Parts
Animation Reference