Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Add sound effect to animation clips

Discussion in 'Animation' started by zsolt67, Aug 9, 2016.

  1. zsolt67

    zsolt67

    Joined:
    Jun 21, 2016
    Posts:
    19
    Is there a simple way ,extension or anything whics makes this part of the animation making easy?
    I saw Cinema director which ok for cutscene but I would like to add sound effect for animation clips.
     
  2. catherineproulx

    catherineproulx

    Unity Technologies

    Joined:
    Apr 24, 2014
    Posts:
    16
    You could add a StateMachineBehaviour to the state of the animation to which you want to associate a sound.

    Eg:

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class PlaySound : StateMachineBehaviour
    4. {
    5.  
    6.     override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    7.     {
    8.         animator.gameObject.GetComponent<AudioSource>().Play();
    9.     }
    10.    
    11. }
    12.  
     
  3. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    there is no way to add sound effect directly into an animation clip but you can add Animation Event that are trigger at a specific time define by you, when the callback get called you can start your sound effect.

    By example on a walk animation clip you could add an animation event when one of the foot touch the ground and in the callback start your sound effect for foot step.
     
    JetSmile likes this.
  4. zsolt67

    zsolt67

    Joined:
    Jun 21, 2016
    Posts:
    19
    Thank you. But i am looking for some editor extension or something like that. We have lot of animation and at the moment we screenrecord the animation add sound effect in video editor bec easy to sync the position, lenght etc. Then we save the sound track. Then we have an animation and same lenght sound file. I cannot find anything in asset store which makes this job easy. Cinema director is the only one but that is for cutscenes only
     
  5. zsolt67

    zsolt67

    Joined:
    Jun 21, 2016
    Posts:
    19
    I am new in unity but I cant beleive the way to add sound to the animation only manualy event+code. If somebody running here and there on the screen what is the workflow exactly for all the 132 step's sound effect? add manualy each???
     
  6. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
  7. sandboks

    sandboks

    Joined:
    Oct 21, 2016
    Posts:
    3
    AudioAnimation_ss.png
    Update to 2018 (maybe earlier?) - You can add audio source component attributes to the animation timeline. In my example, I set the audio source component Loop to false, and PlayOnAwake to true. Then set the `enable` state to false on the first frame (and in the idle state). On Frame 2, or whenever you want the sound to start, set `enable` to true. (that is along way around to say `Play()`)

    You can also setup the component to loop and use the volume attribute to fade in or out on the animation timeline.
     
  8. OKOYEDAVE

    OKOYEDAVE

    Joined:
    Dec 2, 2018
    Posts:
    1
    SANDBOKS REPLY IS GOOD
     
  9. JamesWhiteeee

    JamesWhiteeee

    Joined:
    Sep 4, 2018
    Posts:
    1
    Will this stop the sound if the animation stops?
     
  10. GuardHei

    GuardHei

    Joined:
    Feb 10, 2018
    Posts:
    89
    I don't think so. As long as the audio source is enabled and the game object is also active, it should just act like a normal audio player.
     
  11. LilGames

    LilGames

    Joined:
    Mar 30, 2015
    Posts:
    565
    I like this as it's slightly easier than setting up an event, but ultimately this doesn't solve the original problem of not being able to hear sounds in sync with the animation while editing. (Anyone who has used Adobe Flash to animate things knows exactly what I'm talking about. Or Premiere, or any number of video-audio editing tools that have timelines and animation in them.)

    Would TimeLine and Playables help here at all?
     
  12. Loisal

    Loisal

    Joined:
    Apr 17, 2020
    Posts:
    1
    Thank you some much, it really helped to add a footsteps sound !
    (i'm like really really new to unity :) )
     
  13. TheRedGuy90

    TheRedGuy90

    Joined:
    Dec 5, 2014
    Posts:
    117
    Can we change the audio source, fade out one and fade new in this way?

    also, what about footfalls when animating player walking?
     
  14. LilGames

    LilGames

    Joined:
    Mar 30, 2015
    Posts:
    565
    There are tutorials on this. Check the "Standard Assets" FPS sample project.
     
  15. vive_creative

    vive_creative

    Joined:
    Mar 22, 2019
    Posts:
    12
    Syncing sounds via animation event is not intuitive. It could be a lot easier if we had an option to see sound waves in the animation editor itself & then sync like a pro. Unity could be listening hopefully?
     
  16. quint_unity

    quint_unity

    Joined:
    Oct 11, 2020
    Posts:
    13
    Please implement this functionality!
     
  17. Fomin

    Fomin

    Joined:
    Dec 4, 2014
    Posts:
    9
    this is what I really need
     
    M_R_M and LilGames like this.
  18. jungledong

    jungledong

    Joined:
    Mar 12, 2016
    Posts:
    1
    disable AudioSource Component in Prefab Play on Awake set true.then set AudioSource enable in animation key frames
     
  19. LilGames

    LilGames

    Joined:
    Mar 30, 2015
    Posts:
    565
    Do you add multiple audioSource components (for many SFX?)
     
  20. Hazneliel

    Hazneliel

    Joined:
    Nov 14, 2013
    Posts:
    305
    This is exactly what I was thinking. I need to sync some laughing animation to the laughing audio clip and is hard to know at which frames I should open the mouth to match the audio clip. LipSyncing solutions wont help me much with laughing animations. If only I could see the Audio Wave in pair with the animation frames would be super helpful.