During game development, audio often takes a backseat. Resources and time for its creation and setup are allocated on an as-needed basis. However, sounds and music are powerful tools that can significantly improve the gaming experience. They enrich feedback, excellently convey atmosphere and emotions, and help to reveal the symbolism of the events unfolding.
What's most important is that even the best masterpiece from a talented sound designer or composer cannot fully realize its potential if it fails to be organically integrated into the gameplay process. Here, both virtual space availability and overall interactive experience need to be taken into account.
In Nau Engine, we incorporated existing industry approaches as well as developed our own tools for solving typical problems that arise during development.
To bring sound to the game, you'll need:
- import files into the project in accordance with general rules,
- add sounds to a "container", group them together, and set up overall logic for playing them back,
- create an object on the stage with an "emitter" component that will playback the container's contents,
- create an object on the stage with a "listener" component that will pick up the played sounds.
Below we'll consider each step as well as options available to developers responsible for audio content in games.
Importing Audio
The path of audio content in development begins with its importation. Nau Engine supports the following formats: WAV and MP3.
To add needed files to the project:
- Click the "+" Add button in the top-left corner of the project browser.
- Drag-and-drop assets from the system file explorer into the project browser window in the editor.
- Move the desired files via the system file explorer to a project folder (either the root directory or a subfolder).
For more information on importing, please refer to the documentation article.
In any case, the audio file will be added to the project folder as an unprocessed asset. Now it can be used when setting up the audio container - an abstract asset that groups sounds and helps set basic playback logic for them.
Container
A container is an asset that contains one or more audio tracks and describes the logic of their playback.
You can create a container in any folder of your project. To do this, select "Audio Container" from the dropdown menu:
- By clicking the "+" Add button
- By right-clicking on empty space in the project browser
By selecting the container, you will open its settings in the inspector. You can add one or more imported files to the list, with the same sound being added multiple times.
Next, you can configure the playback parameters of the container's overall content using dropdown menus. The following types of container playback are available:
- Sequence: plays all sounds in order
- Random: plays one random sound
- Shuffle: plays all sounds in a random order
- Mix: combines the sounds in the container into a single track
Both individual files on the list and the entire container can be played by clicking the audio_play button (play automatically).
Adding to the Scene
To add sound to a game, you need to create objects on the scene with the following components: "emitter", which is responsible for playing the sound, and "listener", which will receive it.
In some cases, audio is not tied to a specific point in space, such as background music or ambient sounds. In these situations, the placement of objects with components does not have great importance. However, in most cases, the placement of sounds in space plays an important role. For example, if a character moves through a forest where birds are chirping and a river is flowing, incorrect placement of emitters responsible for bird chirps and running water can ruin the immersive feeling of the game.
The general rule: assign the "listener" component to the object representing the player's avatar on the scene. On the other hand, add the "emitter" component with the corresponding container settings to the "sound-emitting" objects.
In the emitter, you can:
- Add a link to the container that will be played
- Specify whether the sound will play when the scene starts or needs to be activated (for example, from scripts)
- Specify if the sound will loop when played
- Set up whether the sound is bound to space (3D) or not (2D), and in the first case, set its shape and size
You can also interact with containers directly through code by connecting them to event logic.
After the scene is ready, you can check its overall sound by starting Play mode. Don't be afraid to experiment and enjoy the creative process!