Best practice to switch BGM music?

Hi

I have a beat’em up type game, in which need to change the BGM according to player status, if the player is in danger state, current BGM need to be quickly fade out, a in-danger BGM fade in then. And if the player gets a heal and back to normal state, the in-danger BGM fades out, and the regular BGM fades in.

My current solution is to create a parameter event, use a parameter sheet which has NORMAL/DANGER enum, and set player state when player’s state changes. The fade-in fade-out stuff are done in fmod studio.

This works fine for one level, however, the designers want to configure different BGMs for different levels, so in current approach, I have to duplicate the same event and replace the assets in the sheet. This doesn’t seems to be scalable, especially if the switching logic changes, I have to make changes on each level’s BGM event.

So I’m curious, are there better way to work with this kind of requirements, like “template of complicated event”?

Thanks a lot!

There is no one objectively-best way to do this. Every approach has advantages and disadvantages, and will make certain things harder tor easier.

Every possible way of structuring your event logic will be robust in the face of certain requirement changes and yet fragile in the face of others. Without knowing how your game’s requirements are likely to change in future, it is impossible to recommend any particular way of structuring your events.

That being said…

Have you considered not building the music track switching logic into your events at all? You haven’t mentioned that you need to keep combat and non-combat tracks in sync; if you do not need to do so, a simple solution might be to construct each of your music tracks as a different event, each with an AHDSR modulator on its master track volume to allow the event to fade in or out when started or stopped, and allow the track selection logic to be handled entirely by your game’s code.

Alternatively, if you do need the normal and danger music tracks for a location to be controlled by the same event for any reason, you could potentially use programmer instruments instead of single instruments or multi instruments. When triggered, a programmer instrument provides a callback prompting your game’s code to specify which asset should be played, so this could allow you to use just one event to play the music for all of your game’s areas, instead of having to create a different version of that event for each location in your game.

Thanks for such a detailed answer!

Finally I decided to go the second way (making each track a separate event and let the switching logic happen in game code)

Thanks a lot!