# Playing audio from an audio clip reference in Unity

**URL:** <https://qa.fmod.com/t/playing-audio-from-an-audio-clip-reference-in-unity/18680>\
**Category:** Unity\
**Tags:** csharp, cpp\
**Created:** [April 19, 2022, 8:29pm UTC](https://qa.fmod.com/t/playing-audio-from-an-audio-clip-reference-in-unity/18680 "2022-04-19T20:29:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![regularfriend](https://avatars.discourse-cdn.com/v4/letter/r/439d5e/32.png) [@regularfriend](https://qa.fmod.com/u/regularfriend)\
**Post date:** [April 19, 2022, 8:29pm UTC](https://qa.fmod.com/t/playing-audio-from-an-audio-clip-reference-in-unity/18680/1 "2022-04-19T20:29:35Z")

</div>

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.

> [@Programmable Sounds in Unity](https://qa.fmod.com/t/programmable-sounds-in-unity/13350):
>
> Hi, I’m having an issue getting programmable sounds to work in Unity with FMOD. I’m basing my test off of the example script in [your documentation](http://www.fmod.org/documentation#content/generated/engine_new_unity/script_example_programmersounds.html). I’ve managed to trigger the example event ok with the programmer sound when its created by passing in a key from an audio table. For my project though I will require the ability to create a programmer sound from a Unity AudioClip and pass that to the event with the programmer sound. I’ve managed to create the FMOD sound ok from an Audio Clip using c…

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](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.

---

<div class="post-metadata">

**Author:** ![regularfriend](https://avatars.discourse-cdn.com/v4/letter/r/439d5e/32.png) [@regularfriend](https://qa.fmod.com/u/regularfriend)\
**Post date:** [April 22, 2022, 12:56am UTC](https://qa.fmod.com/t/playing-audio-from-an-audio-clip-reference-in-unity/18680/2 "2022-04-22T00:56:49Z")

</div>

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
