Search Unity

Access Audio Track Volume

Discussion in 'Timeline' started by mutafikah, Jul 24, 2018.

  1. mutafikah

    mutafikah

    Joined:
    Jul 3, 2018
    Posts:
    5
    I have an audio track on a timeline. I'd like to be able to change the volume of this track by code. I've tried accessing the volume of the audiosource which is attached to it, but this doesn't change the timeline's volume. Is there a way to access the volume of a timeline audio track?

    Thanks!
     
  2. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    No, but it's something we are looking to add soon.
     
    awsapps, FURKANKAHVECI and mutafikah like this.
  3. FURKANKAHVECI

    FURKANKAHVECI

    Joined:
    May 12, 2013
    Posts:
    27
    2019.1 ?
     
  4. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    Volume in 2019.1, animated volume in 2019.2.
     
    FURKANKAHVECI likes this.
  5. Wrymnn

    Wrymnn

    Joined:
    Sep 24, 2014
    Posts:
    384
    I have taken look at AudioTrack, but still cannot find volume accessor/setter. Using Unity 2019.2.8
     
  6. ewanuno

    ewanuno

    Joined:
    May 11, 2017
    Posts:
    58
    assign an Audiosource to the Audiotrack, then control the volume of that Audiosource, either directly or via a mixer.
     
  7. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    The volume can be accessed from the inspector, or from the the curve editor. If you select a clip, you can edit the volume in the inspector (but it is not animated, except for using ease/blend in/out).

    upload_2019-10-24_8-17-30.png
     
  8. Ilya_Krav

    Ilya_Krav

    Joined:
    Jul 27, 2019
    Posts:
    2
    Is it added?
     
  9. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    Yes, from 2019.1 if I recall correctly.
     
  10. Ilya_Krav

    Ilya_Krav

    Joined:
    Jul 27, 2019
    Posts:
    2
    Can you tell me how to use by code?
     
  11. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    Unfortunately, the necessary fields don't seem to in the public API so it can't be used to set their value directly.

    However, you can set an animated value for them using the following:

    Code (CSharp):
    1. audioTrack.CreateCurves("nameOfAnimationClip");
    2. audioTrack.curves.SetCurve(string.Empty, typeof(AudioTrack), "volume", AnimationCurve.Linear(0,0,1,1));
    3. audioTrack.curves.SetCurve(string.Empty, typeof(AudioTrack), "stereoPan", AnimationCurve.Linear(0,-1,1,1));
    4. audioTrack.curves.SetCurve(string.Empty, typeof(AudioTrack), "spatialBlend", AnimationCurve.Linear(0,0,1,1));