Contribute on GitHub

Adding Sounds to Your Module

Bannerlord audio system is built on proprietary FMOD Sound system. To keep audio engine performant while making it accessible to anyone, we needed to create an interlayer.

Key Elements

You can see examples in ‘Native’ module.

Basic Guide

  1. Copy example files and folder to your own module
  2. Add new sounds into the ModuleSounds folder
  3. Open the module_sounds.xml of your module
  4. You will see sound categories, code example for playing sounds and example module_sound entries in the original module_sounds.xml file
  5. Add new entry to your mod’s module_sounds.xml
  6. Play the new sound entry from the code

Moving Further

Using module_sounds.xml

    <module_sound name="example/combat/hit" is_2d="true" sound_category="mission_combat" path="example_sound_modders.ogg" />

Playing Sound from Code Example

    int soundIndex = SoundEvent.GetEventIdFromString("example/voice/charge"); //to avoid string operations in runtime soundIndex can be cached.
    if (playOneshot)
    {
        MakeSound(soundIndex, MainAgent.Position, false, true, -1, -1); //plays one shot sound at position with given parameters.
    }
    else
    {
        SoundEvent eventRef = SoundEvent.CreateEvent(soundIndex, Scene); //get a reference to sound and update parameters later.
        eventRef.SetPosition(MainAgent.Position);
        eventRef.Play();
    }

You have two ways to play sound: