Skip to content

Added ModAudio #51

Open
KenCagg wants to merge 4 commits intoAlchyr:masterfrom
KenCagg:master
Open

Added ModAudio #51
KenCagg wants to merge 4 commits intoAlchyr:masterfrom
KenCagg:master

Conversation

@KenCagg
Copy link

@KenCagg KenCagg commented Mar 20, 2026

Credit: Original approach by cany0udance, adapted for BaseLib as ModAudio.

What it does
Loads .ogg files from your mod’s Godot project using a resource path to the audio folder (the folder that contains sfx and bgm), so you don’t hard-code full paths everywhere.

Folder layout (your audio folder, e.g. res://ThePaladin/audio)

Sound effects: sfx/.ogg
Optional subfolder: sfx//.ogg
Music / ambience: bgm/.ogg
Hook it to your character

On your CustomCharacterModel, override CustomAudioPath and return that audio path (e.g. res://TheCharacter/audio).
Use ModAudio.PlaySfx("Name", volumeDb) etc. from your mod. If you only use one audio root, BaseLib infers it when your character is constructed; you can still call ModAudio.SetRoot to override or when you have multiple roots.
Optional: ModAudio.Register("your_character_id", "res://YourMod/audio") for id-based overloads, or ModAudio.DiscoverPlaceholderCharacters() for PlaceholderCharacterModel discovery.
Playing audio
Use ModAudio (PlaySfx, Play with optional folder, PlayGlobalSfx, PlayMusic, fades, ambience, …). Use SetRoot, a character id, or a CustomCharacterModel reference when you need to pick between multiple roots.

Note: Combat SFX attach to the combat room when it exists; global SFX use the scene tree as implemented in **ModAudio.

Example

If you have an audio file named SFX_Boom.ogg in your res://TheCharacter/audio/sfx folder:

using BaseLib.Utils;

in your customcharacter.cs:
public override string? CustomAudioPath => "res://TheCharacter/audio";

then somewhere in your class e.g. (example from rhythm girl card)
ModAudio.PlaySfx("SFX_JabExhaust", 5f);

@KenCagg KenCagg changed the title Added ModAudioHub Added ModAudio Mar 20, 2026
@Alchyr
Copy link
Owner

Alchyr commented Mar 21, 2026

I probably won't be merging this for a few reasons;
current code is a little bit too unnecessarily specific in how it's used with CustomCharacterModel
second, I'm looking into playing sounds through fmod, the main audio engine the game is using
I've got that partially working, but it only loads files included in the game's .pck and not those loaded through mods, so I'm gonna see if I can do anything about that
If I can't, then I'll probably just end up using AudioStreamPlayer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants