I’d like to know if it’s possible to enable and disable tracks of a sequence by scripting at runtime. I’m creating a procedural soundtrack whoose have three differents sounds that plays at the same time.
So for example, when the enemy is far away, i’d like to only play the first. When the enemy is at medium range, i’d like to play two and when he is chasing you i’d like to play all the three sounds.
Because of this sounds must be synced, i have each one in a different sound track.
I readed the documentation and didn’t found anything about controlling tracks.
Enable/Disable tracks is possible but please note that is only when the cutscene is not already playing. If the cutscene is already playing then unfortunately that is (at least right now) not possible.
To enable/disable a track, you need to use the API to find that track. This is done with the ‘Cutscene.FindElement(string path)’ method. For this to work, you need to manually name the Group as well as the Track you want to find (done in the inspector of Group and Track respectively).
So, for example if you want to find an Audio Track that you have named “MyTrack”, and which lives under a Group which you have named “MyGroup”, you can then do this:
I think that won’t do it, because i need to change those tracks at runtime while the sequence is playing so i can “hide” the audio in that track.
But now thinking a little about it, perhaps I could change the Master Volume property in the Track to mute the audio at runtime, without having the desync problem.
Yes, your suggested solution will work just fine 🙂
Also, if you end up linking the Audio Tracks to a Unity Audio Mixer (possible in the Audio Track inspector), you can also control the audio through that Audio Mixer.
– _masterVolume is protected and doesn’t have any way to access it.
– Then I tried to setup an audio mixer and change it’s “Attenuation – Volume” but it doens’t seems to work. It barelly reduces the sound of it.
I could hack it, by creating a way to access the _masterVolume property and re-apply the SetAndApplySettings method, so probably if I create my own Audio Track extending from the original, with that accessor i could fix the problem.
public float MasterVolume
{
get => _masterVolume;
set {
_masterVolume = value;
SetAndApplySettings();
}
}
Or maybe I’m just complicating the solution, have any idea?
Hm. I am not sure why setting the mixer volume did not work for you.
I can add a public method for setting the volume like this in AudioTrack.cs similar to what you suggest.
If it helps you achieve what you want, I will leave it there officially for the next version as well 🙂
Alright then. I will leave the SetVolume method there for the next version. You can open up AudioTrack.cs and add the method as posted above now in your project so that you can use it. When you update Slate in the future it will be there 🙂