Is Adding Custom Audio Assets Supported For Mods Yet?

Discuss modding questions and implementation details.
Post Reply
User avatar
Magicono43
Posts: 361
Joined: Tue Nov 06, 2018 7:06 am

Is Adding Custom Audio Assets Supported For Mods Yet?

Post by Magicono43 » Sun Jun 28, 2020 3:13 pm

As the title says, like if I wanted to add a custom "one-shot" sound effect whenever one of my modded items is used, would this currently be possible for a mod or no? I know that the quest engine now supports adding music at specific triggers, but only from the audio assets already in the game, is that correct?

User avatar
pango
Posts: 2407
Joined: Wed Jul 18, 2018 6:14 pm
Location: France
Contact:

Re: Is Adding Custom Audio Assets Supported For Mods Yet?

Post by pango » Sun Jun 28, 2020 5:10 pm

I think this has already been answered (or at least partially) in this thread: a mod can load sounds and play them, directly calling Unity.
That should work but does not satisfy me completely, as Daggerfall Unity takes care of some extra features, like background loading, or scaling volume with general sound effects volume... so there could be some duplicated code (and/or discrepancies).
When a measure becomes a target, it ceases to be a good measure.
-- Charles Goodhart

User avatar
Hazelnut
Posts: 2218
Joined: Sat Aug 26, 2017 2:46 pm
Contact:

Re: Is Adding Custom Audio Assets Supported For Mods Yet?

Post by Hazelnut » Sun Jun 28, 2020 5:38 pm

It's the equip and swing sounds where you're restricted to the enum of DF sounds, you can play any sound you like via Unity in the item use handler code you write.
See my mod code for examples of how to change various aspects of DFU: https://github.com/ajrb/dfunity-mods

User avatar
Magicono43
Posts: 361
Joined: Tue Nov 06, 2018 7:06 am

Re: Is Adding Custom Audio Assets Supported For Mods Yet?

Post by Magicono43 » Sun Jun 28, 2020 6:57 pm

Thanks for the replies, well that's good to hear then, I thought there were currently more restrictions than that I suppose, but i'll see how the result sounds when I do try to add some audio files in.

l3lessed
Posts: 433
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: Is Adding Custom Audio Assets Supported For Mods Yet?

Post by l3lessed » Mon Jun 29, 2020 3:52 pm

This can be done through the unity engine from what I see. There are two possible ways to do this. The first is the easiest, but I do not think it will compile the custom audio clip properly, but you can try anyways. I know the second will work, but it relies on hard coding C# to force the custom clips into the engine for detection and playing.

The first is done by using the editor to attach a audio clip to a newly created gameObject, which would be added by the mod. Follow the below directions.
  • You create your game gameObject that will hold and play the audio clip; I imagine this should be the mod object/script. The script/gameObject now has a audioclip attached to it.
  • Now the unity engine needs to know when and how to play it. This could be done by setting it to play onwake on the clip settings so it automatically plays the sound anytime the script/object is called (As an example, a generated game statue could play a sound when it appears). Or, this can be, like in the linked example, tied to a simple key press or even possible looped timer if you want a looped sound of some type.
  • Now you have custom sounds.
https://www.studytonight.com/game-devel ... o-in-unity

I don't know how well this will compile though, since it relies on attaching the clip through unity engine and its gameObjects. I do not know, if compiling the clip into the mod json would ensure the directory information for retrieving and playing it when the json is loaded remains intact.

Try it out and let me know. :twisted:

If the mod builder doesn't transfer the attached audio clip information, as I think it won't, you will then need to manually load, via the script code itself, the audio file and attach it to a source, so the unity engine can still play it after properly compiled. Just like my shield textures, ensure the clip directory paths are correctly setup for yourself and users installing the mod files.

Here is a quick example of how to manually load in these audio clips into unity via code. This example, while still not 100% the most efficient, is a great place to build from. It will load not only a single file, but a while directory, and allow you to select each audio clip in that directory.

https://answers.unity.com/questions/156 ... ory-a.html

Follow the below directions to hard code in your custom audio clip.
  • Create a directory inside the streaming asset folder that will hold all your custom sound files you want to play in your mod and drop all your custom audio clips in it.
  • Create the script file for the mod that will manually load the audio clip files. Use the above script link as a base to build yours from.
  • Now the unity engine needs to know when and how to play all these custom loaded clips. This could be done by setting it to play onwake on the clip settings so it automatically plays the sound anytime the script/object is called (As an example, a generated game statue could play a sound when it appears). Or, this can be, like in the linked example, tied to a simple key press or even possible looped timer if you want a looped sound of some type.
  • Now you have custom sounds.
The above method, while coding centered and a bit harder to get implemented, should work no matter what, since the audio clip is being brute loaded through the script code, and not the unity gameObject reference.

Don't forget people, DFU uses the unity engine as a base engine. If DFU engine hasn't had it built in for us modders by the excellent developers here, always see if the base unity engine can force it in through the base engine some how.
Last edited by l3lessed on Mon Jun 29, 2020 4:20 pm, edited 4 times in total.
My Skyrim Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

User avatar
Magicono43
Posts: 361
Joined: Tue Nov 06, 2018 7:06 am

Re: Is Adding Custom Audio Assets Supported For Mods Yet?

Post by Magicono43 » Mon Jun 29, 2020 4:06 pm

I was able to get it to work with the help of example mod 3 in the modding tutorial. I'm not sure if that's the best way to do it, but it seems to "Just work" as Todd would say, so i'm content with that for now at least, lol.

l3lessed
Posts: 433
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: Is Adding Custom Audio Assets Supported For Mods Yet?

Post by l3lessed » Mon Jun 29, 2020 4:18 pm

For sure, that is the most straight forward method. The only advantage I can see the the coding method I provided is the example method above is able to load an endless array of custom sounds into a single directory and call them as needed through the array index, so all custom sounds are stored within a single directory and single object array.
My Skyrim Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

User avatar
Magicono43
Posts: 361
Joined: Tue Nov 06, 2018 7:06 am

Re: Is Adding Custom Audio Assets Supported For Mods Yet?

Post by Magicono43 » Mon Jun 29, 2020 4:32 pm

l3lessed wrote:
Mon Jun 29, 2020 4:18 pm
For sure, that is the most straight forward method. The only advantage I can see the the coding method I provided is the example method above is able to load an endless array of custom sounds into a single directory and call them as needed through the array index, so all custom sounds are stored within a single directory and single object array.
Yeah, I really don't know the significance performance wise of how assets are loaded and such, I generally have not been doing crazy stuff with my assets, which would not make my designs very modular at all, but hey, that's the beauty of mods, just plop it in and hope it does not break, lol. All I have been doing so far with image files and audio files is basically just having them as loose files packaged inside the built mod and retrieving them by name directly. With this example it has those names put into an array which I can then just call the correct index for whatever asset I need, this would potentially be less preferred if I wanted to do some randomly selected ambient noises or something, but in my case I just need one (maybe two) sounds associated with one item, so it works in the most simple implementation.

l3lessed
Posts: 433
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: Is Adding Custom Audio Assets Supported For Mods Yet?

Post by l3lessed » Mon Jun 29, 2020 4:41 pm

Yeah, for a handful of sounds, I would just use the created audio importer.

This would be best, like you said, for any modders who may be needing multiple clip arrays or one really large clip array, especially for any random large clip loop.

Most modding uses, I imagine, will be able to rely on the build in importer. But, if for some odd reason, you find yourself needing to use tons of differing clips or use multiple clip arrays, here is an alternative.
My Skyrim Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

Post Reply