Playing audio from an audio clip reference in Unity

Hey, I am looking to support playing audio from an assigned AudioClip (.wav flie) in the inspector in unity. The main goal of this is to quickly play our current audio without huge reworks so we can continue to have audio while we (more slowly) convert the project to using entirely proper Fmod events.

Reading through the documentation, it seems like programmer sounds can do what I need to do for this, but the example case is based on loading the audio through a resources folder (with a string reference) rather than directly accessing the audio clip itself. I see from a few years back there was a question here on how to instantiate a programmer sound using an audio clip, but the syntax seems out dated and before I try to adapt it to use the more modern API, I want to make sure this is the right design pattern to do so.

It seems like here you basically take the audio clip, pack it as an array of byte data and then send that info to FMOD and create the sound. Is this still the way to do this? If not, what is the proper way to do this. The code in this post doesn’t work as some of the api calls (particularly the one to get the low level system) are outdated, but if this design pattern is basically correct I can base what I do off of this and figure it out. I just want to make sure its conceptually sound before doing so.

One idea i had is to just get the filepath from the assigned audio clip and then do something more similar to the programmer sound example here:

https://www.fmod.com/resources/documentation-unity?version=2.01&page=examples-programmer-sounds.html

My main concern with this is that it would not work in builds unless I moved every audio clip currently in our game into a resources folder and I’d rather not do that if it’s avoidable.

I implemented it based off the design pattern in the first post i linked. Had to change a few things to match the updated API but works as intended. This thread can be closed, just posting here so future readers can see that this design pattern still works in 2022

1 Like