Audio files in Resources subfolder

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
urrmurrmur
Posts: 47
Joined: Wed May 05, 2021 1:57 pm

Audio files in Resources subfolder

Post by urrmurrmur »

Hi,

My project is configured to use a default sequence as follows:

Code: Select all

SALSA(entrytag);
Delay({{end}});
Which works fine as long as all my audiofiles are in the main Resources folder. I'd like to organize them by scene though, which I can also make work by prepending the entrytag in the above sequence with the subfolder for that particular scene. However, if I do that, I also need to prepend that folder every time I want to make a dialogue state with a custom sequence, and since I have a few scenes set up already, that would break some of my dialogues temporarily.

Granted, this is a minor convenience issue and not a big deal in the slightest. I was wondering though if there is an option somewhere to force the dialogue manager to scan through all Resource subfolders (or all of the ones that are marked as relevant somehow) when looking for a file with a particular entrytag name. If such an option does not exist, I'm considering adapting the source code to include it, depending on how complex it is. In that case, could you point me towards the method I'd have to update to implement this functionality?
User avatar
Tony Li
Posts: 22145
Joined: Thu Jul 18, 2013 1:27 pm

Re: Audio files in Resources subfolder

Post by Tony Li »

Hi,

The Dialogue System uses Unity's Resources.Load<T> method, which doesn't scan subfolders. It tries to load from a specific path.

Here are some ideas:

1. Use Addressables instead. The steps to switch are:
  • Import Unity's Addressables package.
  • In the Dialogue System's Welcome Window, tick the USE_ADDRESSABLES checkbox.
  • Move your audio files into the root of Resources folders.
  • Tick the audio files' Addressable checkboxes. Unity will ask if you want to move the audio files out of the Resources folder(s). Click yes. When Unity moves the files, it will set their Addressable keys to the name of the audio file. AudioWait(entrytag) will look up Addressable audio files by this key. Make sure to move the audio files into the root of Resources folders before ticking the Addressable checkbox; otherwise this process will include the path inside the Resources folder in the key.
  • You don't need to do anything else. The Dialogue System will automatically use the audio files just like they were in Resources, except you don't need to worry about where in the project they're located.
2. Or change the path from this (for example):
  • Assets / Resources / Audio / NPCs / Adam / Adam_1_1.wav
to this:
  • Assets / Audio / NPCs / Adam / Resources / Adam_1_1.wav
Then you can use AudioWait(Adam_1_1) and the Dialogue System will be able to find the audio file.

3. Or set a DS variable to the name of the scene. For example:

Code: Select all

void Awake() 
{ 
    DialogueLua.SetVariable("scene", SceneManager.GetActiveScene().name);
}
and use this sequencer command, assuming the audio files are in Resources/scene/:

Code: Select all

AudioWait([var=scene]/entrytag)
urrmurrmur
Posts: 47
Joined: Wed May 05, 2021 1:57 pm

Re: Audio files in Resources subfolder

Post by urrmurrmur »

Thanks Tony, fast and helpful as ever. I went with the folder restructuring approach for now, since it's a quick fix and it makes sense to have all my sound files in the same root folder anyway. Might switch to using addressables later, but this solution works fine.
User avatar
Tony Li
Posts: 22145
Joined: Thu Jul 18, 2013 1:27 pm

Re: Audio files in Resources subfolder

Post by Tony Li »

Great! Glad to help.
Post Reply