Skip to content

Audio system

Ciro Continisio edited this page Jul 30, 2021 · 2 revisions

Audio in Chop Chop is played with Unity's native AudioSource and AudioListener components without any external middleware, and we have built a layer on top to help manage audio requests from different entities in the game.

Table of contents

Audio Manager

The AudioManager is a script sitting in the PersistentManagers scene, which is a scene loaded at all times (see here for more info). Being in a separate scene means it can manage audio and potentially cross-fade music across scenes without interruption.

At the beginning of the game, the Audio Manager creates a pool of SoundEmitter objects, each one with its own AudioSource. It then listens on two event channels, PlaySFX and PlayMusic, for requests coming from other objects. Once it receives a request it will pass it onto one of the SoundEmitters in the pool and play music or an SFX.

Audio requests travelling on an AudioCueEventChannel bear three main parameters: the AudioCueSO they want to play, the AudioConfig which determines "how" the sound is played, and the position for 3D sounds.

When playing an SFX, the Audio Manager will rely on a collection of emitters of type SoundEmitterVault, which, through an AudioCueKey identifier, finds which of the objects in the pool is busy with playing which sound(s). We have a structure for playing multiple SFXs at the same time as if they were one, allowing designers to create composite sounds from within Unity (see AudioCueSO below).

When playing music, it will always just go to the same SoundEmitter and ask it to play, fade in or out, or stop. We don't currently have support for cross-fading music.

Audio Manager script

Sound Emitters

The SoundEmitter scripts receive direct orders from the AudioManager to play sounds. From there, they take control of a sound and they notify the AudioManager when they are done (for non-looping sounds), which puts them back into the available pool. Example methods are PlayAudioClip, FadeMusicIn, FadeMusicOut, Pause, Resume, Stop, Finish, and more.

A SoundEmitter takes care of only one sound, so for composite SFX multiple SoundEmitter instances receive the request, each one spinning up its own AudioSource. In fact, some of them might be "done" before others, and go back in the pool before the whole SFX is over.

Sound Emitters pool

Audio Cue ScriptableObjects

An AudioCueSO is a ScriptableObject that acts as an index of individual AudioClips that make up a complex sound. If multiple AudioClips belong to the same group, they can be played in random order or with the same order every time.

Audio Cue SO to play a composite sound The sound for the cooking pot is a looping sound, made up of two different SFXs (fire and boiling water) of different lenghts

Audio Cue SO to play a random sound from a list The sound for the player receiving a hit is randomly selected from 3 different clips each time, and it doesn't loop

Audio Cue components

The AudioCue class is a component added to Prefabs in the scene, to create positional 3D sounds that can be placed and configured by a designer, and which will usually play as soon as the scene starts. An example of this are the torches, the cooking pot, the waterfall, and other environmental sounds.

The Audio Cue component

Audio Cues can also be played by another script, but this is rarely used in the game.

Home
Video materials

Basics

World building and Graphics

Game architecture

The game systems explained, with API examples. For programmers.

Game design

How-tos for designers to expand the game's gameplay.

  • Adding quests
  • Adding items
  • Creating dialogues
  • Making a cutscene
Clone this wiki locally