Making Music React to Gameplay [Part 2]
In the previous post, we prepared an ADX Cue Sheet containing a main music Cue, as well as Cues for extra musical phrases and kicks that can be added on top of it. We set up Actions and Game Variables to start these extra sounds based on the situation in the game, and in sync with the background music. In this post, we will import the data authored in AtomCraft into Unreal Engine and implement it in the game with a Blueprint.
Importing the Cue Sheet
To add the binary Cue Sheet to your game project, import the .acb and .acf files that were built into the content drawer (content browser).
The .acf file contains all the Atom Craft project information. When importing, you will be asked if you want to update the Atom plug-in with the Atom Configuration contained in this file; press “Yes”.
The assets will be created.
If you open the Cue Sheet and try playing Cue_BGM, you can verify that all the settings from Atom Craft have been carried over, such as other Cues being triggered at the timing set in the Action Track.
Playing the BGM
However, what we want to do is to play the BGM from the Level’s Blueprint.
First, open the editor via “Open Level Blueprint”.
Then, place a Spawn Sound 2D node.
Be sure to select this node from the Atom category, and not the one under the Audio category, as it is UE’s default, and it would not be able to play Atom cues.
If you start the game, the BGM will now play just like it did in AtomCraft’s preview mode, and the secondary sounds triggered by Actions will also play correctly.
Selecting Sounds with Game Variables
Finally, let’s change the Game Variable and confirm that the sound changes.
• After we start the playback by pressing the “1” key, we use a Set Atom Game Variable node to set the variable to 0.0.
• When we press the “2” key, we do the same but set the variable to 1.0.
This way, pressing 1 or 2 will trigger a different sound variation.
Stopping the current BGM
If you press the keys several times, you will notice that, right now, pressing a key triggers a new sound on top of the old one.
Let’s add a way to stop the current sound before starting a new playback.
First, Right-click the blue output pin of the Spawn Sound 2D node and select Promote to Variable.
This turns the Atom cue (technically, the Atom Component) into a variable.
A Set node will be created. Place it after the Spawn Sound 2D node.
Now, when playback starts, if there is already a sound playing, it will be removed (DestroyComponent) before starting a new playback.
You can see the entire setup below:
With this Blueprint, you will not have to restart the game every time to test playback.
This was just a simple example: ADX’s Actions can do a lot more than just trigger playback; they can also change sound parameters or branch between sounds in different ways. Because the properties of the triggered tracks are also inherited, this becomes a powerful tool for creative audio implementations.