Skip to main content
‹ Back to Tutorials
Intermediate Unity

Unity 3D & Playmaker - Setting Animation Events that are triggered from the Animation Timeline

Mar 24, 2021
About this tutorial

In this tutorial I'll cover setting up Animation Events. An Animation Event allows you to call a function in C# or in my case a Playmaker FSM Event at a specific point from an animation. EXTREMELY USEFUL. Also check out How to Make a Bounce Game Series https://bit.ly/39HIYBU. 👉🏼 To Sign up for

Written Guide

Animation Events let you trigger something at an exact moment in an animation's timeline, calling a C# function or, as in this tutorial, a Playmaker FSM event. That timing precision is extremely useful: here a character fires two weapons, and we want a blaster sound to play precisely when each shot goes off, plus a quick light flash, all driven by a small sound manager.

Building the Sound Manager

Create an empty game object named game manager and, inside it, a sound manager. Add an FSM, leave the default state named start, and add a new event called blaster. Then add a global transition for the blaster event by right or control clicking and choosing Add Global Transition, which lets this state be reached from anywhere. Name that state blaster as well, and in it add a Play Sound action loaded with the sci-fi blaster clip. Now whenever the blaster event fires, the sound plays.

Relaying the Event From the Character

The animation lives on the character, so it needs its own FSM to forward the call. Add an FSM to the character with a start state and a new event named trigger blaster sound, again wired as a global transition. In the trigger blaster sound state, add a Send Event by Name action, which lets one FSM talk to another. Point it at the sound manager game object and call the blaster event. So the chain is: animation fires trigger blaster sound on the character, which relays to the sound manager's blaster event, which plays the clip.

Placing Animation Events on the Timeline

Open the character's attack animation, which fires the blaster twice. In the Animation window, right click in the gray bar just above the keyframes and choose Add Animation Event at the exact frame where the first shot fires, then add a second event at the second shot. Each event offers many function options; choose the one that sends an event as a string, and type the string trigger blaster sound, the name the character's FSM is listening for, into both events. Playing the animation now triggers the sound right on each shot. Making the clip loop with Loop Time enabled makes testing more lively.

Adding a Light Flash

For extra punch, add a Point Light to the scene in front of the character, tint it toward a pink-purple, and raise its color value and intensity. Because the light should only appear during a shot, deactivate it in the scene to start. In the sound manager's blaster state, add an Activate Game Object action turning the point light on alongside the sound. Add a finished transition to a wait state with a short Wait of 0.3 seconds, then another state named turn light off that copies the Activate Game Object action but deactivates the light, with a finished transition back to start. The result is a synchronized sound and light flash that fire exactly with the animation, a technique you can reuse for footsteps, impacts, or any precisely timed effect.

Unity tools by Bliz Studio
Built for our own games — now on the Asset Store

Multi Tag — unlimited hierarchical tags for any GameObject. Hierarchy Pro — style your whole hierarchy with rules. Made by a Unity dev, for Unity devs.

Explore our Unity assets →