Using a script to add an audio clip onto a Timeline.

Ok, so this might seem like a weird question, but trust me it’s for a good reason!

What I essentially want to do is take an AudioClip reference that i have (eg myAudioClip), and then in a script, put myAudioClip at the beginning of the Timeline, then play the Timeline.

So far, I’m using UnityEngine.Playables and UnityEngine.Timeline. And I can say myPlayableDirector.Play() to start the Timeline whenever I want, which is good…

However, that’s about as far as I got, unfortunately. Any help on this would be greatly greatly appreciated!

Thank you!

Once you have created a PlayableDirector and a Timeline, you can add an AudioTrack:

var track = myTimelineAsset.CreateTrack<AudioTrack>(null, "myTrack");

Then you can create a clip on that track

var clip = track.CreateDefaultClip();

then you can cast that clip as an AudioPlayableAsset and set the AudioClip

var audioPlayableAsset = clip.asset as AudioPlayableAsset;
audioPlayableAsset.clip = myAudioClip;
4 Likes

Thank you so much Julien!

1 Like

hi i looking for custom UnityEngine.Timeline.AudioPlayableAsset
like add more option in inspector after loop
any help please thank’s