Search Unity

  1. All Pro and Enterprise subscribers: find helpful & inspiring creative, tech, and business know-how in the new Unity Success Hub. Sign in to stay up to date.
    Dismiss Notice
  2. Dismiss Notice

Bug a problem In AudioClipPlayable (also In TimeLine)

Discussion in 'Timeline' started by unity_kib9wyhppu, Dec 29, 2020.

  1. unity_kib9wyhppu

    unity_kib9wyhppu

    Joined:
    Oct 29, 2020
    Posts:
    1
    I found a problem that if use audioClipPlayable to play a short audioClip (about 0.1 seconds), it will cut off the first period of time( about 2 frames, 0.03s).
    Code (CSharp):
    1.  
    2. [RequireComponent(typeof(AudioSource))]
    3. public class AudioClipPlayableTest : MonoBehaviour
    4. {
    5.      //This AduioClip's length is 0.1s
    6.      public AudioClip audioClip;
    7.      public AudioClipPlayable clipPlayable;
    8.      public PlayableGraph graph;
    9.      public AudioPlayableOutput output;
    10.      public AudioSource audioSource;
    11.      void Start()
    12.      {
    13.          CreateGraph();
    14.      }
    15.      void OnGUI()
    16.      {
    17.          if (GUILayout.Button("play"))
    18.          {
    19.              if (clipPlayable.IsDone())
    20.              {
    21.                  graph.Stop();
    22.                  graph.Destroy();
    23.                  CreateGraph();
    24.              }
    25.              graph.Play();
    26.          }
    27.          if (GUILayout.Button("stop"))
    28.          {
    29.              graph.Stop();
    30.              graph.Destroy();
    31.          }
    32.      }
    33.      void OnDestroy()
    34.      {
    35.          if (graph.IsValid())
    36.          {
    37.              graph.Stop();
    38.              graph.Destroy();
    39.          }
    40.      }
    41.      private void CreateGraph()
    42.      {
    43.          audioSource = GetComponent<AudioSource>();
    44.          graph = PlayableGraph.Create("Test");
    45.          output = AudioPlayableOutput.Create(graph, "output", audioSource);
    46.          clipPlayable = AudioClipPlayable.Create(graph, audioClip, false);
    47.          output.SetSourcePlayable(clipPlayable);
    48.      }
    49. }
    50.  
    I also found the same problem In TimeLine(the timeLine is base on playable system),if you put a short audioClip to audio track,and set the start time to 0, then play this timeLine track,you will found the sound is different to the audioClip.

    I'm not sure This applies to audio of all lengths.The longer the audio length, the smaller the proportion of 0.03 seconds in it, and the less perceptible it is.

    Most ui sound effects are about 0.1 second in length.And I don't know how to avoid this Problem. : (
     

    Attached Files:

unityunity