How to sync audio with Animation in Unity?

Ever had the problem of audio not playing in sync with your animation? Do you find your player movement not synchronized with the movement sound you added? The problem occurs due to non-usage of an animation event.

Let’s try to understand this.

Say you have a player attack animation where the player unsheathes and swings the sword. if you have a sound that needs to play exactly when the player swings the sword and not while he unsheathes it. How to do that? Here is a step-by-step tutorial to play the sound in the animation frame of your choice.

Animation Event tutorial

  • Add an audio source to your character and assign the audio clip you need to play.
  • Disable play on Awake in the audio source.
  • Create a new script and add a public function like the one below.
public void play_clip()
  • Select your animation and go to the inspector window.
  • You can also do it from the animation window as shown in the YouTube tutorial above.
  • Scroll down until you see the event section.
  • Expand and click on the add event button on the left top.
  • Drag the cursor to the time where you want the audio to play.
  • Assign your script to the event object.
  • Type the function name in the event function variable.
  • Add you script as a component to the character.
animation event window

Now your audio clip will play at the exact time you have mentioned in your event. If you are having any trouble leave a comment below.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.