DynamicMusic

A DynamicMusic instance lets you play multiple music tracks simultaneously, perfectly synchronized. It’s perfect for adaptive soundtracks where different instrumental layers (e.g., drums, strings, vocals) are turned on or off at runtime based on gameplay. Use the same music tracks you created in the Audio Creator window under the Music tab.


🛠 How to create a DynamicMusic

Group your pre-created tracks by their tags or by the Track enum identifiers. For example, to build a layered theme:

new DynamicMusic("BaseTrack", "Drums", "Strings").Play();

Or using the Track enum directly:

new DynamicMusic(Track.BaseTrack, Track.Drums, Track.Strings).Play();

If you rename a track’s tag in the Audio Collection window, any code reference will break.

DynamicMusic intenseTheme = new DynamicMusic(Track.Base, Track.Choirs)
    .SetLoop(true)            // Loop all stems indefinitely
    .SetAllVolumes(0.5f);     // Set every layer to 50% volume
intenseTheme.Play();

📝 Advanced Example

DynamicMusic adaptiveSoundtrack = new DynamicMusic(
        Track.MainTheme,
        Track.Percussion,
        Track.Violins
    )
    .SetAllVolumes(0.7f)                  // Base volume for all stems
    .SetTrackVolume(Track.Percussion, 0)  // Start with percussion muted
    .SetLoop(true)
    .SetOutput(Output.Music)
    .OnPlay(() => Debug.Log("Soundtrack started!"))
    .Play();

// Later, during combat:
adaptiveSoundtrack.ChangeTrackVolume(Track.Percussion, 0.7f); // Bring in percussion

👉 This sets up an adaptive soundtrack that begins with a soft base layer and then intensifies by bringing in percussion when combat begins.

Last updated