Enable and disable tracks by script

Slate Forums Support Enable and disable tracks by script

Tagged: 

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #2117
    haytam95
    Participant

    Hi!

    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.

    Thank you!

    #2118
    Gavalakis
    Keymaster

    Hello there,

    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:

    cutscene.FindElement<CutsceneTrack>("MyGroup/MyTrack").isActive = false

    Please let me know if that works for you.

    Thanks 🙂

    Join us on Discord: https://discord.gg/97q2Rjh

    #2119
    haytam95
    Participant

    Hi Gavalakis, thanks for your response.

    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.

    That could work, right?

    #2120
    Gavalakis
    Keymaster

    Hello again,

    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.

    Both solutions are fine though.

    Join us on Discord: https://discord.gg/97q2Rjh

    #2132
    haytam95
    Participant

    Hi Gavalakis

    I couldn’t make work any of the solutions.

    – _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?

    #2133
    Gavalakis
    Keymaster

    Hello again,

    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 🙂

    Let me know.

    Join us on Discord: https://discord.gg/97q2Rjh

    #2134
    haytam95
    Participant

    That would be great Gavalakis, thanks!

    Hm. I am not sure why setting the mixer volume did not work for you.

    This is what I did:

    – Created an Audio Mixer Group.

    – Exposed the param “Attenuation” in it, as “Volume”.

    – Added the Audio Mixer Group to the track.

    – From my code retrieved the Audio Mixer Group reference from the Track and set the value using .SetFloat(“Volume”, myFloatVariable);

    (I’m not great at playing with sounds, perhaps I made a silly mistake and exposed the incorrect parameter now that I’m thinking of it…).

    I think that expose the method “SetVolume” however, will be a nice way to quickly change that without needing to play around with audio mixers.

    #2135
    Gavalakis
    Keymaster

    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 🙂

    Thanks.

    Join us on Discord: https://discord.gg/97q2Rjh

    #2142
    haytam95
    Participant

    Thanks Gavalakis!

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.