|
Post by someguy989283 on May 4, 2021 18:05:52 GMT
Hi team,
Just started with this asset. I am triggering many of the sounds I have via code. Is there any way to select which sound group that I'd like to play besides by passing a string? If I change the name of the sound group, it will all break. I don't like hardcoding anything, especially with strings.
What's the best practice here?
|
|
|
Post by DarkTonic Dev on May 4, 2021 18:10:37 GMT
You don't hard-code. You make the Sound Group string variable an exposed public field in your script. And you can decorate it with an attribute that lets you select the Sound Group from a dropdown.
[SoundGroup] public string JumpSound;
// later MasterAudio.PlaySound3DAtTransformAndForget(JumpSound);
However, Event Sounds, Ambient Sounds, Mechanim State Sounds should save you from having to write code in almost every circumstance. You can even use Event Sounds in an Animation Event.
If you need to change the Group's name, you should first find all references to the Sound Group in the Scene by clicking the magnifying glass icon in its row in the Master Audio mixer section, then you can re-select all of them with the new name. It won't find things in your own custom scripts but it will find the rest. Your scripts that try to play a non-existent group will log an error to the Console so you can find them as well, at runtime.
In the early days the sounds were an enum and that was a major hassle to edit it every time you added a Sound Group and compile. Definitely not the way to go.
-Brian
|
|
|
Post by someguy989283 on May 5, 2021 3:36:22 GMT
You don't hard-code. You make the Sound Group string variable an exposed public field in your script. You can also decorate it with an attribute that lets you select the Sound Group from a dropdown, which is great. [SoundGroup] public string JumpSound;
// later MasterAudio.PlaySound3DAtTransformAndForget(JumpSound);
However, Event Sounds, Ambient Sounds, Mechanim State Sounds should save you from having to write code in almost every circumstance. You can even use Event Sounds in an Animation Event. If you need to change the Group's name, you should first find all references to the Sound Group in the Scene by clicking the magnifying glass icon in its row in the Master Audio mixer section, then you can re-select all of them with the new name. It won't find things in your own custom scripts but it will find the rest. Your scripts that try to play a non-existent group will log an error to the Console so you can find them as well, at runtime. In the early days the sounds were an enum and that was a major hassle to edit it every time you added a Sound Group and compile. Definitely not the way to go. -Brian Ah I see! Thank you!
|
|
|
Post by DarkTonic Dev on May 5, 2021 3:52:50 GMT
No problem!
|
|
|
Post by Someguy on May 5, 2021 13:46:20 GMT
PS: I understated my thanks. THANK YOU. This is an INCREDIBLE asset. I set up dynamically generated dialog made up of many different chopped up WAV files, forming full coherent sentences with various and the like, all easily last night. The fast response you gave really set me up for success - amazing!
|
|
|
Post by DarkTonic Dev on May 5, 2021 14:55:28 GMT
That sounds killer! If you have a chance to show that off in a video sometime, please share. We made the asset for ourselves because there was nothing good enough out there, then decided it would be great to share with others.
-Brian
|
|
|
Post by Some Guy on May 6, 2021 16:56:47 GMT
It's mostly just general "status" type of text using nested IF statements.
If (team == "player") { play "our team is down to.wav"
else( play "Enemy team is down to"
if(oldPercent >75 && newPercent <=75){ play "75 percent")
if(this) play that
A bit more logic, like checking to see what conditions exit, if the coroutine is done or if something is playing it should wait to be played or not, lots of variants for soundgroups, etc, but very easily done.
|
|
|
Post by Some Guy on May 6, 2021 17:37:02 GMT
PS: Noticing a bit of a delay between the sounds being played - 99% due to my code Is there a best practice to follow for creating dynamic dialogue?
|
|
|
Post by Some Guy on May 6, 2021 17:39:37 GMT
Or perhaps, is there a Native way to build a list/array to the Playaudio function to play them in succession? I can build that array and finally add them all to the coroutine. I think I can build that on my own, but if you have your own function for that, it'd be ideal, just curious
|
|
|
Post by DarkTonic Dev on May 6, 2021 18:56:50 GMT
Or perhaps, is there a Native way to build a list/array to the Playaudio function to play them in succession? I can build that array and finally add them all to the coroutine. I think I can build that on my own, but if you have your own function for that, it'd be ideal, just curious Yes there's an example here, under "Chaining Sounds Together". There's another way too with setting the SoundFinished delegate of each sound you play. www.dtdevtools.com/docs/masteraudio/TriggeringAudioCoding.htmLatency will exist only if you haven't already preloaded the audio data, by using Resource Files, Addressables, turning off Preload Audio Data, etc. And that's up to you.
|
|