Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Audio Get Audio Attenuation during Timeline

Discussion in 'Audio & Video' started by Jason-RT-Bond, Jul 25, 2020.

  1. Jason-RT-Bond

    Jason-RT-Bond

    Joined:
    Mar 26, 2012
    Posts:
    64
    I'm looking to control a simple 2D animation based on the attenuation of audio clips being played on an audio source.

    Ordinarily, I'd do something like...
    Code (CSharp):
    1. audioSource.clip.GetData (audioData, audioSource.timeSamples)
    ...and then check the largest value in audioData and use that as the approximate current attenuation. That's crude, but suits my purposes and can be used to flap a mouth to a variety of audio without manual animation work.

    However, it looks like audioSource.clip is never assigned when audio is played using Timeline, even if the audioSource is assigned to the track (this is optional but impacts settings). Does anyone know an alternative approach which would work with Timeline? I really want to avoid adding a new custom Timeline track to control this animation manually.

    Any suggestions welcome :)
     
  2. Jason-RT-Bond

    Jason-RT-Bond

    Joined:
    Mar 26, 2012
    Posts:
    64
    Silly of me not to have found this earlier: https://docs.unity3d.com/ScriptReference/AudioSource.GetOutputData.html

    Very similar call made to the AudioSource itself WORKS! Automatic mouth-flapping success!

    However, one issue which I suppose is more of a Timeline problem: This call ONLY works at runtime, and returns empty when the Timeline is playing during edit time.
     
unityunity