Tutorial: How to import custom sounds to in-game

Modding is not officially supported. Take backups of game and save files before modding. Do at your own risk.

Updated:
You can use C# and Mod Loader to load AudioClip using Unity's WWW -class. Here is an example taken from my Recorder Flute -mod:

Code:
// Load .wav file using WWW -class.
WWW RecorderSound = new WWW("file:///" + @Path.Combine(ModLoader.GetModAssetsFolder(this), "g5.wav"));
while (!RecorderSound.isDone) { }; // Wait sound to be loaded.

// Add clip to recorder flute.
RecorderPivot.GetComponent<AudioSource>().clip = RecorderSound.GetAudioClip(false);


To replace existing sounds, you need to find the according AudioSource that holds the clip you want to replace. There is many way to acquire it; one approach could be scanning through all AudioSources with foreach -loop and check if the clip name of AudioSource matches to one you are replacing.

Pseudo-Example:

Code:
foreach(AudioSource audio in GameObject.FindObjectsOfType<AudioSource>())
        {
            if(audio.clip.name == "ClipToReplace")
            {
                // Load .wav file using WWW -class.
                WWW NewSound = new WWW("file:///" + @Path.Combine(ModLoader.GetModAssetsFolder(this), "g5.wav"));
                while (!NewSound.isDone) { }; // Wait sound to be loaded.

                audio.clip = NewSound.GetAudioClip(true); // Change clip to AudioSource
            }
        }


OUTDATED METHOD:

Needed programs:
- Unity
- Unity Asset Bundle Extractor
- Soundfile (.wav)
- Notepad


Use Unity Asset Bundle Extractor to find an AudioClip to replace from mysummercar_Data/sharedassets2.assets. Rename your .wav file with that name.

1.) Open Unity and make new project.
2.) Copy your .wav file to your projects Assets/ -folder.
3.) Add a new GameObject to scene and add Audio Source component to it.
4.) Drag & Drop your .wav file to AudioSources AudioClip -field.
5.) In File -> Build Settings, add your scene to build and click Build to build your project somewhere.
6.) Find your buildedprojectname_Data/ and files "sharedassets0" and "sharedassets0.assets.resS" (it name may be sharedassets0.resource too) .
7.) Rename "sharedassets0.assets.resS" file anything you want (for ex. "hayosikosounds.resource") and copy it to mysummercar_Data/ -folder
8.) Use Unity Assets Bundle Extractor to Export your AudioClip to 'Dump' from buildedprojectname_Data/sharedassets0.assets file.
9.) Open the Dump file in Notepad and find following line: 1 string m_Source = "sharedassets0.assets.resS" and change that to point your resource file ("hayosikosounds.resource").
10.) In Unity Assets Bundle Extractor, open mysummercar_Data\sharedassets2.assets file and find the original AudioClip
11.) Click "Import Dump" and select file you previously extracted
12.) Use File -> Mod Maker -> Create standalone .exe installer to create installer and save it to MSC root folder
13.) Run installer.

Let me know if there are succes or problems with this, or is this readable at all...
 
Last edited:
Hello, I'm having an issue with step 8. When I import my sharedassets0.assets file from the project UABE will not respond and eventually crash. Is there any other steps I'm missing when setting up the unity project? Thanks!

EDIT: I figured it out, I was using a very old version of UABE for some reason, got the newest version and all worked well!
 
Last edited:
Not sure if it's fitting though, but I guess so...
So how would I go about exporting an AudioSource to use in a mod I'm writing using MSCLoader?
I updated first post to show example, how to load new samples using C# and Mod Loader. If you want to export .wav:s from the game itself, i suggest you to use UABE as it can export sound files to .wav.

However if you want to export sounds with Mod Loader -script while in-game, i'm not entirely sure how to do that, but maybe you can try something like this: https://gist.github.com/darktable/2317063
 
I'm struggling at number 8. When I try to Export Dump, it says:"The file format is empty!"
Latest version of UABE. Please help!

Edit:
Don't worry, I've figured out that I've should to Export Dump from SharedAssets.assets:)
 
Last edited:
@M
Not sure if it's fitting though, but I guess so...
So how would I go about exporting an AudioSource to use in a mod I'm writing using MSCLoader?
Are you using dev tool kit mod? if so, type "MasterAudio" and a most of of the audio sources are there: For example if you would want to get the "assemble" sound you would go,
Code:
GameObject.Find("MasterAudio/CarBuilding/assemble").GetComponent<AudioSource>().Play();
You need to set the position of the audio. (at least in my xp) so:
Code:
AudioSource assembleAudio = GameObject.Find("MasterAudio/CarBuilding/assemble").GetComponent<AudioSource>();
assembleAudio.transform.position = new Vector3(); // the position you want
assembleAudio.Play();
But not all sounds are located there. In another instance i needed to get the button click noise from the dashboard. and that was just located under:
Code:
GameObject.Find("dash_button").GetComponent<AudioSource>();
 
I get it of this way:
1.) Open Unity and make new project.
2.) Copy your .wav file to your projects Assets/ -folder.
3.)->no necessary
4.) Drag & Drop your .wav file to AudioSources AudioClip -field.
5.) In File -> Build Settings, add your scene to build and click Build to build your project somewhere.
6.) Find your buildedprojectname_Data/ and files "sharedassets0" and "sharedassets0.assets.resS" (it name may be sharedassets0.resource too) .
7.) Rename "sharedassets0.assets.resS" file anything you want (for ex. "hayosikosounds.resource") and copy it to mysummercar_Data/ -folder
8.) Use Unity Assets Bundle Extractor to Export your AudioClip to 'Dump' from buildedprojectname_Data/sharedassets0.assets file.
9.) Open the Dump file in Notepad and find following line: 1 string m_Source = "sharedassets0.assets.resS" and change that to point your resource file ("hayosikosounds.resource").
10.) In Unity Assets Bundle Extractor, open mysummercar_Data\sharedassets2.assets file and find the original AudioClip
11.) Click "Import Dump" and select file you previously extracted
12.) Save it in Desktop and then copy and replace it into mysummercar_Data if you get "cannot open the file for writing "

Thanks!!!
 
big bump, but my code isn't working. The code throws no errors in VS, but the sound isn't replaced in game and performance drops to around 20-30 fps the output.log says my mod has a "System.NullReferenceException: Object reference not set to an instance of an object." I also noticed the "file:///" string isn't routed properly. It takes me to C:\Windows, therefore it's not reaching my asset folder for the sounds. I'm only trying to change the car door sounds. The AudioSource is under "CarFoley" according to the dev toolkit. I've changed my variables accordingly as well.
 

Latest News

How long have you been simracing

  • < 1 year

    Votes: 88 12.6%
  • < 2 years

    Votes: 63 9.0%
  • < 3 years

    Votes: 72 10.3%
  • < 4 years

    Votes: 44 6.3%
  • < 5 years

    Votes: 98 14.0%
  • < 10 years

    Votes: 96 13.7%
  • < 15 years

    Votes: 60 8.6%
  • < 20 years

    Votes: 40 5.7%
  • < 25 years

    Votes: 33 4.7%
  • Ok, I am a dinosaur

    Votes: 106 15.1%
Back
Top