Unity Game Audio Implementation

Unity Game Audio Implementation offers a unique, practical, project-based approach to learning about aspects of Interactive Game Audio for those who have never used a game engine before and don’t want to learn computer programming right now.

The book offers insight into the skills needed to design game-ready sounds using your current Digital Audio Workstation (DAW) and shows how to implement these sounds within the Unity video game engine. The reader will also learn about interactive music and how to set this up to respond to a variety of events in the game, with the option of adding in their own story and dialogue.

All the information is presented in a practical working context from an established Game Audio Sound Designer with AAA games experience. The chapters are accompanied by several game levels teaching you all about the techniques and theories before offering instructive steps for how to put them into action. After completing the practical tasks in this book, only will you create an interactive soundscape for a multilevel playable game featuring all your own audio, you will also receive tips on how to use your finished project in support of an application for Video Game Sound Designer jobs.

Andrew Coggan is a Game Audio Sound Designer with a portfolio of work that includes projects at a number of notable companies such as Travellers’ Tales Fusion on LEGO® STAR WARS™: The Force Awakens, LEGO® MARVEL’s Avengers, various Virtual Reality (VR)/Augmented Reality (AR) experiences and applications, and several independent games spanning a number of different genres. He was also Audio Lead for Cosmonaut Studios on the game Eternal Threads and for Skyhook Games on Lawn Mowing Simulator. In addition to this, an unreleased project called The Seer was featured by Unity at the 2016 international Game Developers Conference (GDC) in San Francisco, California, USA.

Unity Game Audio Implementation

A Practical Guide for Beginners

Andrew Coggan

Cover image: © finevector / Getty Images

First published 2022
by Routledge
2 Park Square, Milton Park, Abingdon, Oxon OX14 4RN

and by Routledge
605 Third Avenue, New York, NY 10158

Routledge is an imprint of the Taylor & Francis Group, an informa business

© 2022 Andrew Coggan

The right of Andrew Coggan to be identified as author of this work has been asserted in accordance with sections 77 and 78 of the Copyright, Designs and Patents Act 1988.

All rights reserved. No part of this book may be reprinted or reproduced or utilised in any form or by any electronic, mechanical, or other means, now known or hereafter invented, including photocopying and recording, or in any information storage or retrieval system, without permission in writing from the publishers.

Trademark notice: Product or corporate names may be trademarks or registered trademarks, and are used only for identification and explanation without intent to infringe.

British Library Cataloguing-in-Publication Data
A catalogue record for this book is available from the British Library

Library of Congress Cataloging-in-Publication Data

Names: Coggan, Andrew, author.

Title: Unity Game Audio Implementation : a practical guide for beginners / Andrew Coggan.

Description: Abingdon, Oxon ; New York, NY : Routledge, 2022. | Includes bibliographical references and index.

Identifiers: LCCN 2021027859 (print) | LCCN 2021027860 (ebook)

Subjects: LCSH: Computer sound processing. | Video games—Sound effects. | Sound design.

Classification: LCC TK7881.4 .C63 2022 (print) | LCC TK7881.4 (ebook) DDC 621.389/3—dc23

LC record available at https://lccn.loc.gov/2021027859

LC ebook record available at https://lccn.loc.gov/2021027860

ISBN: 978-0-367-51774-8 (hbk)
ISBN: 978-0-367-51773-1 (pbk)
ISBN: 978-1-003-05516-7 (ebk)

DOI: 10.4324/9781003055167

Typeset in Times New Roman
by Apex CoVantage, LLC

Access the Support Material: http://www.routledge.com/9780367517731

Illustrations

Figures

1.1.1 Unity Create Account Webpage

1.1.2 Unity HUB Download Webpage

1.1.3 Unity HUB Launch Screen

1.1.4 Creating New Unity Project Screen

1.1.5 Adding and Opening an Existing Unity Project

1.1.6 Unity Project Folder Structure

1.1.7 Unity HUB Error when Attempting to Add a Unity Project from an Incorrect Folder

1.1.8 Unsupported Build Target Message

1.2.1 Unity Main Window

1.2.2 Unity Project Panel

1.2.3 Unity Project SampleScene

1.2.4 Project Folder in Windows Explorer and Unity Assets Folder

1.2.5 Unity Scene View Panel

1.2.6 Unity Main Menu Tool Icons

1.2.7 Move Tool Axis

1.2.8 Rotate Tool Axis

1.2.9 Scale Tool Axis

1.2.10 Scene View Camera

1.2.11 Scene View Buttons (Left-Hand Side)

1.2.12 Scene View Buttons (Right-Hand Side)

1.2.13 Hierarchy Panel

1.2.14 Drum Auxiliary/Master Structure

1.2.15 Unity Parent/Child GameObject Structure in Scene View

1.2.16 Unity Parent/Child GameObject Structure in Hierarchy

1.2.17 Unity GameObject Disabled

1.2.18 Unity GameObject Enabled

1.2.19 Unity Play Button

1.2.20 GameObject Menu Align with View

1.2.21 Game View Buttons

1.2.22 Inspector Panel

1.2.23 Transform Component

1.3.1 Saving the Scene Using the Save Button

1.3.2 Editor Background Colour

1.3.3 Window/Panel Layouts

1.3.4 Maximize or Close Panel

1.3.5 Panels and Shortcuts

1.4.1 Creating 3D GameObjects

1.4.2 Completed Example Including Parent/Child Hierarchy Organisation

2.2.1 Linear

2.2.2 Non-Linear

3.1.1 Variation Sound Design Layers Original Arrangement

3.1.2 Variation Sound Design Layers Alternate Arrangement

3.1.3 Variation Sound Design Single Layer

3.1.4 Ambience Layering Using Audio Files with Differing Lengths

3.1.5 Creating a Seamless Loop

3.2.1 Audacity Main Window

3.2.2 Audacity Project Window

3.2.3 Audacity Selecting Silence

3.2.4 Audacity Audio File after Silence Trimmed from Start and End

3.2.5 Audacity Fade In

3.2.6 Audacity Normalization

3.2.7 Audacity Normalization Window

3.2.8 Audacity Normalization Window

3.4.1 Screenshot Taken from Unity Viking Village Level

4.1.1 Unity HUB Add Viking Village Silent Project

4.1.2 Viking Village Project Folder

4.1.3 Unsupported Build Target Message

4.1.4 Unity Transport Buttons

4.2.1 Importing Assets Menu

4.2.2 Unity Project Panel

4.2.3 Unity Project Panel and Computer Folder Structure

4.2.4 Folder Example Names in Project Panel

4.2.5 Audio Asset Inspector Parameters

4.2.6 Unity Show Asset in Explorer/Finder

4.3.1 Unity Audio Listener in Viking Village Project

4.3.2 AudioSource Parameters

4.3.3 Adding AudioClip to AudioSource (Select Method)

4.3.4 Adding AudioClip to AudioSource (Drag and Drop Method)

4.3.5 AudioSource with Assigned AudioClip

4.3.6 AudioSource 3D Sound Setting Parameters

4.3.7 Creating an AudioSource

4.3.8 AudioSource Min and Max Distance Gizmo Visualisations

4.3.9 AudioSource Logarithmic Rolloff Volume (Min and Max Distance Set to 5 and 10 Respectively)

4.3.10 AudioSource Linear Rolloff Volume (Min and Max Distance Set to 5 and 10 Respectively)

4.3.11 AudioSource Customised Spatial Blend Curve

4.3.12 Placed AudioSource in Viking Village Level

4.3.13 Copy/Paste AudioSource Parameter Settings

4.3.14 Play Mode Colour Tint (Optional)

4.5.1 Image from Viking Village Scene

5.1.1 GameObject Align with View

5.1.2 Add Rigidbody (Method 1)

5.1.3 Add Rigidbody (Method 2)

5.1.4 Cube Positioned Above ‘Floor’ Cube

5.1.5 Add in a Rigidbody Component

5.1.6 Adding a Box Collider Component

5.1.7 Is Trigger Parameter on Box Collider Component

5.1.8 Example Script with Example Variable Name

5.1.9 Chapter 5 Example Project 2. Variable – Countdown Timer Scene

5.1.10 Countdown_Timer Script Variables

5.1.11 Example Code from Countdown_Timer Script

5.1.12 Count Down from Variable

5.1.13 Text GUI Variable

5.1.14 GameObjects Assigned to Countdown_Timer Script

5.1.15 Unassign Text GUI Variable

5.1.16 Assign Text GameObject into Text GUI Variable on Countdown_Timer Script

5.1.17 Example Script Variable Types

5.1.18 Explosion AudioSource GameObject Parameters

5.1.19 Countdown Timer Expanded Script and GameObjects

5.2.1 Creating Prefab

5.2.2 Prefab Components

5.2.3 Adding Prefabs to Scene

5.2.4 Adding Bounce Material to Cube Prefab Box Collider Material Parameter

5.2.5 Prefab Inspector Buttons

5.2.6 Prefab Overrides

5.2.7 Prefab Override Revert All and Apply All Buttons

5.2.8 Individual Changes to Prefabs in Inspector

5.2.9 Adding AudioSource to Cube

5.2.10 AudioSource Added as Child of Cube Prefab GameObject

5.2.11 Adding and Assigning AudioSource

5.2.12 Using Overrides “Apply All” Button

5.2.13 Cannot Restructure Prefab Message

5.2.14 Save and Close Prefab

5.3.1 Close Tutorials Tab

5.3.2 Scene 2D Button

5.3.3 Level End Point

5.4.1 Goal Open Prefab Button

5.4.2 Goal Script AudioSource Variable

5.4.3 WinAudio GameObject AudioSource

5.4.4 Goal Prefab Open

5.4.5 Fireworks GameObject AudioSource

5.4.6 Beep GameObject AudioSource

5.4.7 Explosion GameObject AudioSource

5.4.8 DX_Mission_Failed GameObject AudioSource

5.5.1 Add Rigidbody Component to Box1 GameObject

5.5.2 LaserLine GameObject AudioSource

5.5.3 SwitchTriangle Prefab Open

5.5.4 Switch Material Highlighter and SwitchAudio AudioSource Variable

5.5.5 SwitchAudio GameObject AudioSource

5.5.6 Box1 Play Audio On Collision Script Variables

5.5.7 Box1 Audio GameObject AudioSource

5.5.8 Box2 Play Audio On Collision Script Variables

5.5.9 Box2 Audio GameObject AudioSource

5.6.1 RoboticArm Prefab Open

5.6.2 RoboticArm GameObject Animator

5.6.3 Close Animator Panel

5.6.4 RoboticArm GameObject AudioSource Parameters

5.7.1 Enemy Prefab Nav Mesh Agent Speed Parameter

5.7.2 AutomaticDoors Door Script, Time Until Close Parameter Settings

5.7.3 MazeGate GameObject AudioSource

5.7.4 GateOpen Animator Panel

5.7.5 MazeGate GameObject AudioSource Parameter Settings

5.7.6 Enemy GameObject Enemy Script AudioClips

5.8.1 Task 4 Mission (Almost) Accomplished Scene Box and Ramp Prefab Locations

5.8.2 DX_Mission_Acomplished GameObject AudioSource

6.1.1 Adding Project to Unity HUB

6.1.2 3D GameKit Project Added to Unity HUB

6.1.3 Unity 3D GameKit Scenes

6.2.1 Unity Project Settings

6.2.2 Unity Quality Settings

6.2.3 Mouse Movement Sensitivity in Game View

6.2.4 Set Keyboard/Controller Input

6.3.1 Silent Audio File in Audio Folder of Project Panel

6.3.2 Unity Console Error when AudioClips Are Missing/Unassigned

6.4.1 Audio Listener Default Location

6.4.2 ----- AUDIO ----- Empty GameObject

6.4.3 Removing Existing Audio Listener Component

6.4.4 Creating New Empty GameObject and Adding Audio Listener Component

6.4.5 Add in Audio Listener Controller Script Component

6.4.6 Assigning CameraRig and Ellen GameObject to Audio Listener Controller Script Variables

6.5.1 Game Audio Workflow Processes

6.5.2 Game Audio Process Including Testing

7.1.1 Adding Collider Component

7.1.2 Box Collider Edit Collider

7.1.3 Box Collider in Scene View

7.1.4 Box Collider in Scene View

7.1.5 Level01 Boss Door Stone Circle Trigger Collider in Scene View

7.1.6 InteractOnTrigger Script Component

7.1.7 InteractOnTrigger Layer Parameter

7.1.8 Ellen GameObject Layer Setting (Player)

7.1.9 Chomper GameObject Layer Setting (Enemy)

7.1.10 Grenadier GameObject Layer Setting (Enemy)

7.1.11 Layer Parameter Button in Inspector

7.1.12 Assigning the Collider Using the Inspector

7.1.13 BossDoorStoneCircleBoom GameObject AudioSource

7.1.14 Adding On Enter () Event to InteractOnTrigger script

7.1.15 Assigning BossDoorStoneCircleBoom GameObject to On Enter () Event and Setting Function to SetActive (bool)

7.1.16 InteractOnTrigger, On Enter () Event, Complete Parameter Settings

7.1.17 BossDoorStoneCircleBoom GameObject Enable During Play

7.1.18 Adding AudioSource Pitch Control to InteractOn Trigger Script

7.1.19 All Possible AudioSource Parameter Settings Available Using InteractOnTrigger Script

7.1.20 Alcove Section Level01

7.1.21 Level01 ReverbZone GameObjects

7.1.22 Trigger Area Alcove in GameObject InteractOnTrigger On Enter () Settings

7.1.23 Trigger Area Alcove Out GameObject InteractOnTrigger On Enter () Settings

7.2.1 Adding Audio Reverb Zone GameObject

7.2.2 Audio Reverb Zone Component Visualisation in Scene View

7.2.3 Audio Reverb Zone Parameters

7.2.4 Unity Audio Reverb Zone Min Max Reverb over Distance

7.2.5 Audio Reverb Zone Presets and User Setting

7.2.6 Audio Reverb Zone Example Low, Mid, and High Parameter Values

7.2.7 Audio Reverb Zone ‘Mid’: Low, Mid, and High Parameter Values

7.3.1 Diagram Showing Spherical AudioSource Min Max Distance in Square Shaped Room

8.2.1 Dialogue Recording Technique Using Condenser Microphone Close to Mouth

8.2.2 Dialogue Recording Technique Using Shotgun Microphone

8.6.1 First Subtitle at Start of Level01

8.6.2 InfoZone GameObjects in Hierarchy

8.6.3 Level01_InfoZone02 GameObject in Hierarchy, Scene View, and Inspector

8.6.4 Localizer GameObject and Translator Script

8.6.5 EnglishInformationPoints Asset Location in Project Panel

8.6.6 EnglishInformationPoints Asset Selected in the Project Panel and Editable in the Inspector Panel

8.6.7 Adding AudioSource GameObject for Dialogue Playback in LVL01_InfoZone02 GameObject

8.6.8 Assigning Dialogue AudioSource to InteractOnTrigger Script

8.6.9 Setting AudioSource.Play and AudioSource.Stop Functions in InteractOnTrigger Script

8.6.10 Level02 EnglishInformationPoints Asset with Additional Phrase Added

9.1.1 Random Audio Player Script Component

9.1.2 Random Audio Player AudioClips Bank

9.1.3 Random Audio Player Overrides

9.1.4 Prefab Restructuring Warning in Hierarchy

9.1.5 Opening Prefab Asset in Prefab Editing Mode

9.1.6 Saving Prefab Modifications

9.2.1 Ellen Character Model

9.2.2 Ellen Player Controller Script with Assigned Random Audio Player GameObjects

9.2.3 Ellen FootstepSource RandomAudioPlayer AudioSource GameObject in Hierarchy and Inspector

9.2.4 Ellen Footstep Overrides on RandomAudioPlayer Script

9.2.5 Ellen HurtSource RandomAudioPlayer AudioSource GameObject

9.2.6 Ellen Staff Weapon HitSound and SwingSound GameObjects in Hierarchy

9.2.7 SplashAudio GameObject Assigned to Splash SFX Variable on Death Volume Script Located on Lvl1_DeathVolume GameObject

9.3.1 Chomper Enemy Model

9.3.2 Chomper RandomAudioPlayer AudioSource GameObjects Assigned to Chomper Behaviour Script

9.4.1 Spitter Enemy Model

9.4.2 Spitter RandomAudioPlayer AudioSource GameObjects Assigned to Spitter Behaviour Script

9.4.3 Spitter Range Weapon Script Containing Spit Prefab Variable

9.4.4 Spit Prefab Location in Project Panel

9.4.5 Spit Travel AudioSource GameObject

9.5.1 Grenadier Enemy Model

9.5.2 Grenadier RandomAudioPlayer AudioSource GameObjects Assigned to Grenadier Behaviour Script

9.5.3 EnergyGrenade Prefab Location in Project Panel

9.5.4 Grenadier ShieldUpPlayer GameObject Assigned to Audio Player On Enable Script

9.5.5 Grenadier Death Event Located on Effect Events Script Linked to DeathEvent GameObject

9.5.6 Grenadier DestroyPlayer AudioSource GameObject in Hierarchy

10.1.1 Destructible Stone Chest Model

10.1.2 DestructibleBox Hierarchy Location

10.1.3 Audio GameObject Containing RandomAudioPlayer and AudioSource Assigned to Damageable On Death () Event

10.1.4 Audio GameObject with AudioSource and RandomAudioPlayer Components

10.1.5 HealthCrate Model

10.1.6 HealthCrate Hierarchy Location

10.1.7 HealthCrate Unopened Looping AudioSource GameObject

10.1.8 HealthCrate OpenAudio GameObject and InteractOnTrigger Assignments

10.2.1 Staff Model

10.2.2 WeaponPedestal GameObject with InteractOnTrigger Script

10.2.3 WeaponPedestal Child GameObject with AudioSource

10.3.1 Door Pressure Pad Model

10.3.2 PressurePad GameObject Hierarchy Locations with Send On Trigger Enter Scripts

10.3.3 Door Model

10.3.4 Door Opening GameObject Hierarchy Location and AudioSource Component

10.4.1 Crystal Model

10.4.2 SwitchCrystal GameObjects Containing Send On Trigger Enter Scripts with CrystalCollectAudio GameObjects Assigned to On Send Audio Variable

10.4.3 SwitchCrystal AmbientAudioBeforeCollection and AmbientAudioAfterCollection GameObjects Assigned to InteractOnTrigger script On Enter () Variables

10.5.1 Moving Platform Model

10.5.2 Moving Platforms Audio Loop GameObject Hierarchy Location and AudioSource Component

10.6.1 Level Transition Gateway at End of Level01 after Grenadier Boss has been Defeated

10.6.2 Hierarchy Location to Add in AudioSource GameObject as Child of TransitionStart GameObject

10.6.3 Spaceship that Appears at the End of Level02

10.6.4 Hierarchy Location to Add in AudioSource GameObject as Child of Dropship GameObject

11.2.1 REAPER Project Featuring Looping Musical Arrangement

11.2.2 Music Arrangement Re-imported as Stereo File in REAPER Project

11.2.3 Editing Original Stereo Musical Arrangement and Placing Small Section on New Track at Start of Arrangement with Fade Out

11.2.4 Splitting Audio File Containing Musical Arrangement at Loop Point

11.2.5 Editing Original Stereo Musical Arrangement and Placing Small Section on New Track at Start of Arrangement with Fade Out

11.2.6 Entire Musical Arrangement

11.2.7 Duplicating Last Bar of Music, Adding to New Track, and Routing to Auxiliary Reverb Track

11.2.8 Created Render of Last Bar of Music with just Reverb and Re-Importing

11.2.9 Editing Reverb Audio File at Loop Point, Moving to Beginning of Arrangement, and Adding Fade Out

11.3.1 Interactive Music Controller Script Component Added to New GameObject

11.3.2 Creating New AudioSource GameObject and Setting to Bypass Reverb Zones and Loop

11.3.3 Creating Adding Secondary AudioSource GameObjects and Assigning to InteractiveMusicController Script

11.3.4 Adding Secondary Interactive Music Script and Sphere Collider Components

11.3.5 Adding AudioSourceFadeInVolume Script to Ambient Music AudioSource GameObject

11.3.6 Creating AudioSource, Assigning AudioClip and Bypass Listener Effects, Bypass Reverb Zones, Play On Awake, and Loop Parameters

11.3.7 Creating Mute Ambient Music GameObject, Adding MuteAudioSource Script Component, and Assigning Ambient Music AudioSource to Variable

11.3.8 Creating UnMute Ambient Music GameObject, Adding UnMuteAudioSource Script Component, and Assigning Ambient Music AudioSource to Variable

11.3.9 Creating Mute Combat Music GameObject, Adding MuteAudioSource Script Component, and Assigning Combat Music AudioSource to Variable

11.3.10 Adding Additional Variables to ToggleGameObjectActive Script and Assigning Combat Music AudioSource and Mute Ambient Music GameObjects

11.3.11 Adding Variables to GrenadierDeadEvent SetGameObjectActive Script and Assigning UnMute Ambient Music and Mute Combat Music GameObjects

12.1.1 Unity Audio Mixer Window Menu

12.1.2 Unity Audio Mixer Panel

12.2.1 Audio Mixer Group Structure and Hierarchy Signal Flow

12.2.2 Unity Audio Mixer Group Hierarchy

12.2.3 Assigning AudioSource to Audio Mixer Group

12.2.4 Adding Effects to Audio Mixer Group

12.2.5 Viewing and Adjusting Audio Mixer Effects in Inspector

12.2.6 Send Effect from Player Death Audio Mixer Group to Ambient SFX Audio Mixer Group

12.2.7 Setting Duck Volume Parameter and Send Level Effects

12.2.8 Audio Mixer Edit in Play Mode Button

12.3.1 Adding Effects to AudioSource Component

12.3.2 Audio Low Pass Filter Effect Configurable on AudioSource 3D Graph

12.3.3 Custom Curve Created for Audio Low Pass Filter Controlling Cut-Off Frequency over Distance

12.4.1 Creating Audio Mixer Snapshots

12.4.2 Renaming Snapshots and Setting Default

12.4.3 Assigning Audio Mixer Snapshots to Start UI Script Variables on MenuCanvas GameObject

12.5.1 Pause Menu Buttons

12.5.2 Button Script Component with AudioClip Variable for On Click Event () Located on UI Button GameObject

12.5.3 Event Trigger Component with AudioClip Variable for Pointer Enter Event () Located on UI Button GameObject

12.5.4 Example Audio Mixer UnPaused Snapshot Settings

12.5.5 Example Audio Mixer Paused Snapshot Settings

12.5.6 Exposing Volume Parameter of Master Fader Using Inspector

12.5.7 Renaming Exposed Volume Parameter of Master Audio Group

12.5.8 Adding Mixer Slider Link Script to Master Volume Slider GameObject and Setting Variables

12.5.9 Confirm Visual Link Between Master Volume Parameter in Scene View Pause Menu and Master Audio Group in Audio Mixer Panel

12.5.10 RandomAudioPlayer GameObjects for Chomper on Front End Scene

12.5.11 Setting 2D Spatial Blend and Stereo Pan Parameters on Front End Chomper AudioSources

13.1.1 AudioCountdownDisable Script as Displayed in Inspector

13.1.2 AudioCountdownEnableObject Script as Displayed in Inspector

13.1.3 AudioDisableAfterFinishPlaying Script as Displayed in Inspector

13.1.4 AudioDisableGameObject Script as Displayed in Inspector

13.1.5 AudioEnableGameObject Script as Displayed in Inspector

13.1.6 AudioListenerController Script as Displayed in Inspector

13.1.7 AudioPlayRandomAudioPlayer Script as Displayed in Inspector

13.1.8 AudioSourceFadeInVolume Script as Displayed in Inspector

13.1.9 AudioSourceFadeInVolume Script as Displayed in Inspector

13.1.10 DamageableEnableGameObject Script as Displayed in Inspector

13.1.11 MuteAudioSource Script as Displayed in Inspector

13.1.12 UnMuteAudioSource Script as Displayed in Inspector

13.1.13 OneShotAudioRandomLocation Script as Displayed in Inspector

13.1.14 AudioTriggerMultiColliders Script as Displayed in Inspector

13.1.15 AudioTriggerMultiColliders Example

13.2.1 Ellen Blue Shield Visuals in Game View

13.2.2 Adding AudioEnableGameObject Script to Ellen_Shield GameObject and Assigning AudioSource

13.2.3 EllenShieldAudio AudioSource Parameters and AudioDisableAfterFinishPlaying Script

13.2.4 Ellen Respawn Visuals in Game View

13.2.5 Added AudioTriggerRandomAudioPlayer GameObject with AudioPlayRandomAudioPlayer Script and Assigned AudioSource GameObject

13.2.6 Staff Weapon Podium in Level01 Game View

13.2.7 Staff Podium Before Collected AudioSource Settings

13.2.8 Moving Platforms Model

13.2.9 Rising Platform Hierarchy with Added Start and End Audio GameObjects

13.2.10 Assigning RisingPlatformEnd GameObject to On Enter () Event Set to RandomAudioPlayer PlayRandomClip () Function

13.2.11 PlatformTriggerAreaBottom GameObject with InteractOnTrigger script featuring Assigned RisingPlatformEnd and RisingPlatformStart GameObjects

13.2.12 Dead ChomperRagdoll Model

13.2.13 Dead ChomperRagdoll Prefab Hierarchy

13.2.14 DeadChomperRagdoll GameObject with Vanish Script and Vanish Random Audio Variable

13.2.15 DeadChomperRagdoll Prefab Hierarchy with VanishAudio GameObject Added

13.2.16 DeadChomperRagdollCollision GameObject with Added InteractOnTrigger Script

13.2.17 Audio Mixer Routing Between Arrival and Idle DropShip Audio Mixer Groups

13.2.18 DropShip Idle Audio Mixer Group with Duck Volume Effect

13.3.1 UI Health Bar Heart Icons

13.3.2 TakeDamageUIAudio AudioSource GameObject Parameters

13.3.3 Ellen Parent GameObject Adding Variables for On Death () and On Receive Damage () Events

13.3.4 Assigned AudioSource GameObjects into Variables

13.3.5 Setting Variable Functions to GameObject SetActive (bool)

13.3.6 AudioSource GameObjects Disabled by Default with Audio DisableAfterFinishPlaying Script Added and Assigned to AudioSource Component Above

13.3.7 GainHealthUIAudio AudioSource GameObject Parameters

13.3.8 Ellen Parent GameObject Adding Variables for On Reset Damage () Event

13.3.9 Assigned GainHealthUIAudio AudioSource GameObject into On Reset Damage () Variable and Set to GameObject.SetActive Function

13.3.10 Creating GameObject with AudioCountdownEnableObject Script Assigned to UnMuteGainHealthAudioSource GameObject

13.3.11 UnMuteGainHealthAudioSource GameObject Disabled by Default with UnMuteAudioSource Script Assigned to GainHealthUIAudio AudioSource

13.3.12 GainHealthUIAudio AudioSource Parameter Settings with AudioDisableAfterFinishPlaying Script

13.3.13 EllenLowHealthAudio AudioSource GameObject Parameter Settings

13.3.14 Adding DamageableEnableGameObject Script to Parent Ellen GameObject and Assigning Parent Ellen GameObject to First Variable and EllenLowHealthAudio GameObject to Third Variable

13.4.1 Subtitle Example in Scene View

13.4.2 Creating SubtitleAppearUIAudio AudioSource GameObject Disabled as Default, Activating PlayOnAwake AudioSource Parameter, and Adding AudioDisableAfterFinishPlaying Component

13.4.3 Adding Variable for On Enter () Event on InfoZone GameObjects Setting Function to GameObject.SetActivate and Assigning SubtitleAppearUIAudio GameObject

13.4.4 Creating SubtitleVanishUIAudio AudioSource GameObject Disabled as Default, Activating PlayOnAwake AudioSource Parameter, and Adding AudioDisableAfterFinishPlaying Component

13.4.5 Adding Variable for On Exit () Event on InfoZone GameObjects Setting Function to GameObject.SetActivate and Assigning SubtitleVanishUIAudio GameObject

13.4.6 Alternative Setup Changing Function to use RandomAudioPlayer PlayRandomClip ()

13.5.1 Window Menu for Profiler Panel

13.5.2 Closing Unnecessary Profiler Modules

13.5.3 Profiler Audio Simple

13.5.4 Profiler Audio Detailed

13.5.5 Audio Asset Optimisation Settings in Inspector

13.6.1 Audio Asset Optimisation Settings in Inspector

13.7.1 Resource use of Compressed Audio by Load Type

14.1.1 Job Titles and Typical Audio Department Structure in AAA Games Development Company

14.3.1 Unity Code on Left, Unreal BLUEPRINTS on Right

Tables

2.2.1 Main Frequency Ranges

13.1.1 Suggested Import Settings for PC/Console

13.1.2 Suggested Import Settings for Mobile

Preface

First, welcome to Unity Game Audio Implementation: A Practical Guide for Beginners!

My name is Andrew Coggan. I have worked in the video game industry primarily as a Sound Designer for a number of notable companies, such as Travellers’ Tales Fusion on LEGO® STAR WARS™: The Force Awakens, LEGO® MARVEL’s Avengers, various Virtual Reality (VR)/Augmented Reality (AR) experiences and applications, and several independent games spanning a number of different genres. I was also Audio Lead for Cosmonaut Studios on the game Eternal Threads and for Skyhook Games on Lawn Mowing Simulator. In addition to this, an unreleased project called The Seer was featured by Unity at the 2016 international Game Developers Conference (GDC) in San Francisco, California, USA.

In addition to working professionally in the video game industry for the last several years, I have taught a Game Audio module in several UK universities, including at the Liverpool Institute of Performing Arts (LIPA) and the British and Irish Modern Music Institute (BIMM) for the Manchester and Berlin campuses.

The material in this book was initially created for teaching in these institutions and has been refined and adapted through several years of student feedback.

The main point that was repeated year after year was that the vast majority of Music Production students wanted to focus on the practical sound/music creation and mixing process, rather than learning more theoretical-based gameplay programming and scripting skills. The second point was that students wanted to have as much control over the audio and narrative of the game as possible.

When putting everything together for this book, the core approach I’ve taken to the structure reflects these points of feedback. I think it is most important that when you read descriptions of the processes, you feel not as if you have been given instructions for flat-pack furniture, but rather like you’ve opened a big box of assorted LEGO® and can now build whatever you want. This book will provide you with tools that will allow you to be creative rather than a list of strict rules or step-by-step instructions with no additional context. In cases where a creative decision has to be made by you, several options and their effects and outcomes will be explained. This will enable you to make an informed choice, helping you to shape the audio experience of the game to be as individual as you are. Game Development and Audio Production is a creative field. Video games, even within the same genre, do not all sound the same, nor should they. There are many different ways for you to put your own stamp on the practical projects.

Who this book is for

This book was written for people who want to get started making their own Sound Effects (SFX), dialogue, and music, and then learn how to implement these into a fully playable game, focusing on the Unity game engine (without having to first delve straight into mastering a myriad of computer skills).

This book will introduce you to the concepts of Game Audio and guide you through the process of creating and implementing interactive SFX, dialogue, and music in a provided, prebuilt, third-person platformer game using a step-by-step, start to finish, project-based approach. All without writing a single line of code!

Coding can seem like a scary or daunting task when beginning to learn about Game Development, as it has a very steep learning curve. It requires a lot of theoretical knowledge and an understanding of many different systems before being able to integrate the interactive audio elements. To put this in perspective, I completed work on several professionally released video games before really making progress with learning how to code myself.

This book will not attempt to provide you with all the knowledge you will need to be a completely self-sufficient game developer capable of creating an entire game by yourself. It will not focus on art, animation, or game mechanics programming, but it will enable you to start the journey, focusing solely on the audio side of Game Development from the perspective of a newcomer to Video Game Audio Development.

If you have some previous experience using Digital Audio Workstations (DAWs) to create sounds or music but have never used a video game engine before, then all you need is your computer, this book, and the accompanying free downloadable resources to take your first steps into video game development.

Creating audio for interactive video games requires a number of considerations, tools, and techniques specific to Game Development when compared with music or sound for film and TV. If you have previous experience with either of these areas, great! You’ve already built up a number of transferable skills that will help you to master the material in this book. If not, don’t worry. You can learn about and begin developing these skills while going through the practical tasks and challenges found at the end of each chapter.

The games industry can be intensely competitive, especially in relation to junior/starting positions in established games companies. Many applicants, when applying for their first Junior Sound Designer job, submit a video featuring sound overlaid onto a pre-captured video clip. While this can effectively show sound design skills, it does not demonstrate to employers any skills in Interactive Audio Implementation.

This book will guide you through this process and offer tips on how to turn your finished game level into a professional showreel that can be used in support of future job applications.

After completing the practical tasks in this book, if you want to develop your skills to become a fully self-sufficient Sound Designer capable of adding in all the required code for the audio (without relying on any other members of a Game Development team, such as programmers), there are a number of other available books and resources listed in the final chapter that can help you continue your journey towards achieving this. At the very least, having already gained an underlying knowledge of the various systems and components that make up the Unity game engine, should make the process of learning coding much less daunting than attempting to learn everything about Game Development all at once.

For educators

As stated earlier, the context and structure of this book was born from my own teaching materials and refined over several years of self-reflection and student feedback. This was gained while delivering a 12-week taught module aimed as an optional module for Level 6, third-year Music Production/Sound Technology university students for several institutions in both the UK and Germany.

As the popularity of Music Production/Sound Technology degree programs has risen dramatically in recent years, the content of the degree programs has also needed to evolve to account for changes in the music industry. There has been a slow shift in teaching institutions from focusing solely on Recording/Mixing music, typical Linear Sound for Moving Picture and Live Sound Reinforcement, to including more specialist subjects such as Interactive Game Audio skills as part of the curriculum.

When teaching myself, each of my lessons would typically last 3 hours.

I typically take 2 hours to go through the examples and concepts in the order they are explained within each particular chapter. I try to encourage class discussion or questions throughout this time related to the topics being discussed. For the last hour, I explain the practical task and am on hand to offer support, feedback, or guidance if the students have any questions or queries when completing the tasks.

I have found that in a 12-week structure, for the most part, each chapter within this book relates to a specific weekly lesson, with the exception of combining Chapters 2 and 3 into a single lesson and omitting Chapter 14.

Typically, I would go through the topics in the same sequential order as used within this book.

This existing structure should make it fairly straightforward to create an entire module outline and individual lesson plans; these could be used as presented within this book or easily adapted to fit your own specific requirements. A set of Learning Outcomes or Objectives could also easily be identified using the existing outline of skills and topics within the What this book covers section and also the introductory paragraph for each chapter.

This framework and the content in this book will provide you with all the resources required for an audio industry professional to quickly structure and deliver a typical 12-week taught module. Due to the in-depth explanation of techniques, theory, and processes, it should also be possible for a Music Technology lecturer with a more traditional audio background to learn the required skills and knowledge to deliver a similar 12-week module using these same resources.

What you need for this book

A Windows PC or Apple Mac capable of running Unity (specific requirements are listed in Chapter 1)

An internet connection to download Unity and additional downloadable resources included with this book

Unity version 2019.4.20f1 – released 10th February 2021 (can be downloaded for free)

Any DAW and plugins of your choice

Audacity (can be downloaded for free)

A microphone and a SFX library (free resources provided in downloadable resources)

What this book covers

This book covers a set of easy-to-follow examples, including a number of smaller practical projects and sound design fundamentals in Chapters 1–5; one final larger project is featured throughout Chapters 6–13. This final project uses a pre-constructed, fully functional playable game featuring several levels. A silent version of the final game project is available to download in the included additional resources or Downloadable Content, hereafter referred to as DLC, provided with this book.

When adding all the audio to your own fully functional final playable game, there are a number of creative choices to make. Several options and approaches will be laid out, and the result of each will be explained so that you are able to make an informed creative decision. Using this knowledge and the provided professional tips and tricks will contribute to establishing and accelerating your workflow, enabling you to create a unique audio experience.

In a perfect world, I would advise you to read through the entire book from start to finish before installing Unity; however, I am aware that this is completely unrealistic and that you want to just get stuck in. In this case, I strongly advise that you read through, follow along with the Example Unity Projects, and complete all the practical tasks for each chapter in sequential order. In particular, it is important that you complete Chapters 1 through 7 in sequential order; this is to make sure you gain a baseline knowledge of individual systems within Unity. Successfully completing Chapters 1–7 will guarantee that you are able to assess the various options provided later in the book to best implement your own vision for the main game project. Chapters 8 through 13 discuss the various components of the main game project and can technically be completed in any order you choose; however, again, it is recommended that you work through these in sequential order. I would advise not skipping any of the tasks in Chapters 8 through 12, as this will ensure there are no missing audio elements in your final game project. Finally, I would also advise reading through each chapter carefully before attempting to follow along or complete the practical tasks for that particular chapter. In particular, the 5 quick tips section found at the end of each chapter provide tips, hints, or troubleshooting information that can save you a lot of time and potential frustration when working through the practical exercises.

If you feel you have mastered everything covered so far and now want to improve upon the audio within the game, Chapter 13 will help to elevate your project to the standard expected within a professional game.

As an added bonus, Chapter 14 will talk you through some potential next steps to continue along your journey and how best to turn the work you have put into your final project into what would be expected in an application for a Junior Sound Designer. This advice will help you when trying to land a job with your dream Game Development company.

It is unrealistic to think that you will work through all of the material within this book in a day or two, and attempting to do so likely will not result in the progress you expect.

I would personally advise attempting a chapter or two per week (especially the later chapters), completing the practical tasks as you go. Audio game development will require you to master a variety of complex new knowledge, skills, and working practices that are quite different to any other form of audio production. Game Development can sometimes be frustrating when you are attempting to make your ideas come alive, and quite often the devil is in the details. Remember, it’s perfectly fine to take a break for a few days if you feel yourself becoming fixated on a particular problem at any point. Coming back with a fresh mindset, spotting the obvious problem, and solving an issue you struggled with is one of the most satisfying feelings during development (at least for me).

Chapter 1: Introduction to Game Audio and the Unity game engine

This chapter will introduce you to the Unity game engine; it assumes no prior knowledge of Game Development and will take you step by step through registering and installing the Unity program to creating your first Unity Project.

The practical task at the end of this chapter is to create a 3D model of whatever object you choose. The aim is for you to get used to using the various menus in Unity, focusing upon correct implementation of the Parent/Child Hierarchy.

Chapter 2: Game Audio Sound Design and creation

This chapter discusses the various challenges and requirements that make working in Game Audio so unique. It also highlights various approaches, both hypothetical and practical, regarding the thought process and planning used during the Sound Design process.

The practical task is to revisit some of your favourite games, armed with a new understanding of how sound can be used to establish and influence a wide variety of emotional responses, and to begin critically analysing the audio within these video games.

Chapter 3: Game sound editing techniques

This chapter discusses sound design and best practices regarding the creation of game-ready sound files. It will introduce you to a number of Game Audio-specific sound design techniques and tips that can be applied using any DAW of your choice.

The practical task at the end of this chapter is to plan out how to create an immersive ambience for a small, Viking-themed level, using the theory and techniques you have now gained in the chapter to actually create these SFX.

Chapter 4: Importing assets into Unity and placing sounds in gameworld

This chapter focuses upon how to add the sounds made during the Chapter 3 practical task into Unity. It sets out the methodology/instructions for use of the AudioSource Component and explains the effect the various parameters will have upon sound playback.

The practical task at the end of this chapter will guide you on how best to add, place, and play ambient atmospheric sounds you created in the previous chapter in the same small, Viking-themed level.

Chapter 5: Understanding basic game mechanics and generic Unity tools

This chapter teaches the concept of Game Mechanics; you will learn some of the individual Components of the Unity game engine, with the chapter explaining in detail the function of each individual parameter and, briefly, how these can be applied in the larger scope of Game Audio.

The practical task in this chapter is based on one of the Unity tutorial levels, in which you must use the knowledge gained in this chapter to solve a number of small puzzles successfully in the Unity Editor. As an additional task, you could then replace the existing SFX in this tutorial to use SFX you have created yourself.

Chapter 6: Set up main game project, creating a project plan and Game Audio Design documentation

This chapter goes through the game production process and how sound fits within this. It will introduce you to Game Design Documentation and specifically to Audio Design Documentation. This is used to plan out the project before beginning to make all the sounds, music, and dialogue for the final project.

The practical task for this chapter is to set up and prepare your own audio design documentation for the main game project, similar to any professionally developed game. You can then use this document to help guide your creative choices in the subsequent chapters.

Chapter 7: Game engine tools such as Trigger Areas and Reverb Zones

This chapter builds upon the knowledge of Chapter 5 and introduces a number of more complex Unity Components, again detailing the function of each. In this chapter, you will begin to combine these Components together in a number of ways to produce more complex Game Audio Mechanics.

The practical task in this chapter will expand on the simple ambient SFX covered in Chapter 3. You will be supplied with a fully functioning Unity Script (piece of code) that can be used to modify and control sound using a drag and drop approach, as opposed to directly writing this code yourself. You will be able to turn different SFX on and off and change playback parameters as the playable character walks around the game level to create an interactive and dynamic, changing soundscape.

The practical task is to set up your own Trigger Area and Audio Reverb Zones in the levels for the main game project.

Chapter 8: Recording, processing, and implementing dialogue

This chapter assumes you have some experience with using a microphone to record sounds or musical instruments in a DAW, or are at least somewhat familiar with the process. It will explain the dialogue recording process and introduce you to practical dialogue recording techniques. It will also briefly explore the difference in recording dialogue in film/TV and Game Audio, as games have a number of unique requirements that must be considered when recording and processing dialogue. It will also give practical tips on dialogue recording techniques and solving common problems encountered during the dialogue recording process.

The practical task in this chapter will explain step by step how the current subtitle system in the main example project has been set up and how you can easily change and adapt this if you want to insert your own dialogue and narrative into the game levels.

Chapter 9: Audio Implementation of character and enemy SFX

This chapter will describe several of the existing game mechanics in the final project, demonstrating how the Unity Components covered in Chapters 4, 5, and 7 are used to add SFX to the game. It will explain in step-by-step instructions how each game mechanic works and how audio can be integrated into them using a drag and drop approach rather than code.

The practical task in this chapter is for you to begin to add in your own SFX to the main Unity Project for the Player and Enemy characters described in the chapter.

Chapter 10: Audio Implementation of game mechanics and cutscenes

This chapter will continue to guide you step by step through the remaining game mechanics featured in the project and how to integrate audio into these, much like in Chapter 9.

The practical task in this chapter is for you to create and continue adding your own SFX for mechanics such as Destructible Objects, Weapons, Doors, Cutscenes, and Level Transition areas.

Chapter 11: Interactive music

This chapter will outline how interactive music has been used in a number of popular video games.

If you write your own music, you will be able to add this into the game and make it respond to a number of different events in the levels. If you are not a composer and don’t want to write your own music, a number of included resources will be provided for you to use. With both of these approaches, you will learn how to edit and prepare music tracks for use in an interactive video game.

The practical task in this chapter is for you to choose one of the interactive music solutions offered, or to use the knowledge gained so far, to create your own bespoke interactive music solution and integrate this into the game.

Chapter 12: Unity Mixer routing and effects and additional audio scripts

This chapter will outline the audio mixing process inside Unity. It assumes you will have some familiarity with mixing either music or sound using a mixer alongside audio plugins/processing, again in your DAW of choice. It will also outline a number of commonly used audio effects available inside Unity which are present in the vast majority of DAWs, such as Distortion, Equalisation (EQ) and Reverb.

It will outline the specific Game Audio techniques required for mixing the audio for a game and introduce you to a number of additional premade Audio Tools (Scripts) that have been supplied with this project. These should enable you to accomplish your own interactive audio ideas for the final project, constructing complex behaviour using a modular drag and drop approach.

The practical task in this chapter will instruct you on how to set up the Unity Audio Mixer, assign Unity AudioSource Components to Audio Mixer Groups/Channels and use interactive audio effects on either the AudioSource Component directly or the Unity Mixer to create a dynamic and interactive mix.

Chapter 13: Bonus chapter – expanding/improving upon existing implementation

This chapter is not strictly necessary to complete your interactive Game Audio project, but has been designed for those who have mastered the information presented in earlier chapters and want to challenge themselves. It outlines several methods and steps you could take to improve the original Audio Implementation present in the game to expand upon and add additional audio to several game mechanics. This will enable you to produce a finished final project that would be considered of the quality expected in a professionally released game.

The practical task for this chapter is to follow the step-by-step instructions to implement these additional features on your own project.

Chapter 14: What to do next

This chapter will aim to sum up the book as a whole, putting into context the theory and practical application you have gained. It will also offer additional tips on how to produce a Game Audio demo reel for future job roles and how best to present this to potential employers.

It will also provide recommendations towards additional learning materials depending upon what Game Audio skills you want to further develop in the next stage of your journey.

The practical task for this chapter is to put into place the resources required when applying for the majority of Junior Sound Designer job advertisements.

Glossary of terms

The glossary found at the end of the book will feature brief definitions for the technical terminology used throughout.

New terms and important key words used throughout the entire book are shown in bold.

1 Introduction to Game Audio and the Unity game engine

DOI: 10.4324/9781003055167-1

This chapter will introduce you to the Unity game engine, walking you through the first steps of installing the program and explaining the main menus to help you get stuck in and creating things straight away.

What is Unity?

Unity is an industry standard professional cross-platform game engine.

This essentially means it is just a piece of software used to develop interactive games.

Cross-platform means that developers can simultaneously develop a single game for a wide variety of game consoles and websites. These include PC, Mac, PS5/PS4, Xbox Series X/Xbox Series S, Nintendo Switch, Android and IOS mobile games, and VR systems such as those made by Oculus, HTC, and Sony, to name a few.

What is a game engine?

A game engine is a computer program or collection of programs that game developers use to create and run the game. Game engines will have distinct sets of tools, some of which are shared and some of which are specific to a certain discipline, such as Art, Audio, Programming, Animation etc.

Some long-established developers with large teams, such as Rockstar, the developers of Grand Theft Auto or DICE, the creators of the Battlefield series of games will use their own in-house, bespoke game engine, such as Rockstar’s Advanced Game Engine (RAGE) or DICE’s (Frostbite) Game Engine, solely within their respective Game Development studios. The majority of developers will elect to use a third-party game engine such as Unity, as creating a game engine from scratch takes a considerable amount of time and resources. The other main advantage is that developers who use game engines such as Unity effectively now also gain the benefits of having many software engineers all focused on the sole task of improving existing and developing new features for the game engine. This allows games developers to focus more time on actually making games rather than something potentially less creative, such as a system to better simulate gravity or visual elements such as shadows and reflections. To put this in an audio perspective: if you imagine setting out to record an album for a band, it is much cheaper and easier to buy a license to use an existing DAW or plugin than to commission a software developer to create a whole new DAW or plugin from scratch, just for your particular project.

Unity is the most common game engine used by independent game developers for a number of reasons:

It can produce incredible games

It’s much simpler and faster to use Unity than to create a game engine from scratch

It’s relatively inexpensive

It’s comparatively quick to try out different ideas

Natively cross-platform (can simultaneously develop PlayStation, Xbox, Nintendo Switch, PC games)

It’s widely used by a number of game industry professionals

It has a massive, active online community for additional help

It’s constantly being developed and frequently improved with new features

Should your game require bespoke features, the programmers working on the game alongside you are able to code/create these themselves when required.

Unity has been used to create many, many popular games across a wide range of genres and devices, including:

Cuphead

Hollow Knight

Untitled Goose Game

Call of Duty: Mobile

Fall Guys: Ultimate Knockout

Yooka-Laylee/Yooka-Laylee and the Impossible Layer

Monument Valley/Monument Valley 2

Mario Kart Tour

Super Mario Run

Doom (Nintendo Switch Port/version)

Super Mario Run

Subnautica

Pokémon Go

INSIDE

Escape from Tarkov

Life Is Strange: Before the Storm

Plague Inc./Plague Inc: Evolved

Assassin’s Creed Identity

Kerbal Space Program

Superhot

Praey for the Gods

Beat Sabre (VR)

Firewatch

Ori and the Blind Forest

Cities: Skyline

Hearthstone

Rick and Morty: Virtual Rick-ality (VR)

Downloading Unity

Unity can be downloaded and used for free; using the accompanying installer included in the downloadable additional resources will make this process relatively quick and easy. Unity’s business model is that people like yourself can download and use it for free to learn Game Development.

It is NOT freeware or a demo version that you will use to accompany this book.

The skills and Unity software used in this book are fundamentally the same as used in the games listed on the previous page.

So, if Unity is free, how does ‘Unity Technologies’, the company who develops it, make money?

Unity does offer a paid subscription model, required if the company or game you are developing has revenue or funding of $100,000 or more. (Accurate at time of writing.)

The additional benefits of a paid subscription are that it allows greater access and support for the internal code systems that run inside of Unity, cloud-based diagnostic systems, and analytics to measure things like how many people are currently playing your released game, among other things.

This additional support in the Pro version is mostly for game studios with a number of people all working together on a game designed for commercial release.

When learning Unity using this book, the vast majority of these additional features do not offer benefits that would be particularly valuable to you at this time.

Like many software companies, Unity does release regular updates to the Unity game engine.

These will add additional features and quite often update the requirements for the custom code written for each game. It is very important that you download the corresponding version of Unity for this book to make sure that the accompanying project files will be compatible with this specific Unity version.

The latest version of Unity (at time of writing, currently version 2021) is technically in beta. This means it contains experimental features and is more prone to technical issues, as these features are often in active development. Most professional games studios DO NOT use the latest Unity version, as they are more likely to encounter technical issues. Instead, they tend to use the LTS or Long-Term Support versions featuring smaller incremental updates to the previous main unity version, as these are typically much more stable.

This book will use the Unity version 2019.4.20f1 LTS (Long-Term Support).

Released: 10 February 2021

It can be downloaded from either the Unity website or, preferably, and more easily, by using the installers provided with the accompanying downloadable materials.

Unity is fully compatible with both Mac and PC.

Please check the following ‘detailed requirments’ section to ensure that your computer meets the requirements.

The majority of PC and Apple Mac computers made within the last five years (at time of print) should be capable of running Unity and the associated project files.

Detailed requirements:

PC:

Windows: 7 SP1+, 8, 10, 64-bit versions only

CPU: X64 architecture with SSE2 instruction set support

Graphics API: DX10, DX11, and DX12-capable GPUs

Additional requirements: Hardware vendor officially supported drivers

Apple:

MacOS: Sierra 10.12.6+

CPU: X64 architecture with SSE2 instruction set support

Graphics API: Metal-capable Intel and AMD GPUs

Additional requirements: Apple officially supported drivers

Linux:

Support in preview: Ubuntu 16.04, Ubuntu 18.04, and CentOS 7

CPU: X64 architecture with SSE2 instruction set support

Graphics API: OpenGL 3.2+ or Vulkan-capable, Nvidia, and AMD GPUs.

Additional requirements: Gnome desktop environment running on top of X11 windowing system, Nvidia official proprietary graphics driver, or AMD Mesa graphics driver. Other configuration and user environment as provided stock with the supported distribution (Kernel, Compositor, etc.)

For all operating systems, the Unity Editor is supported on workstations or laptop form factors, running without emulation, container, or compatibility layer.

Tip

To install Unity and download all of the provided resources/project files will require approximately 15GBs of free hard drive space.

It should be noted that all screenshots in this book have been taken on a PC running Windows 10 but that these will directly correspond to Mac OSX.

Creating a free Unity ID

You will also be required to register for a free Unity ID.

You can Google ‘Create a Unity ID’ and click on the links to find the page in Figure 1.1.1 or alternatively type in https://id.unity.com/ in your internet browser.

Figure 1.1.1 Unity Create Account Webpage

Enter your Email, Password, Username, and Full Name before checking the Agree to Unity Terms of Use and Privacy Policy and the reCAPTCHA I’m not a robot checkbox.

Clicking on the Promotional Materials checkbox is optional if you would like to receive promotional material via email.

Once you have completed these steps, click on the green Create a Unity ID Button.

You will receive an email from Unity asking you to confirm your email address.

After clicking on this link, you will now be able to log into https://id.unity.com/.

Installing Unity HUB

Next, you can optionally also install the latest version of the free Unity HUB program.

Unity HUB is an optional standalone application that streamlines the way you find, download, and manage your Unity Projects and installations. It will work similarly to the Project Popup window when launching most major DAWs in that it will show you a number of recent projects, allowing you to open these quickly and easily, along with the associated Unity version used.

I would strongly advise you to download and use Unity HUB to easily manage the numerous Unity Projects included with this book. However, if you do not want to download this, Unity 2019.4.20f1 will work without this additional Unity HUB program.

To download Unity HUB, go to https://unity3d.com/get-unity/download or use the Unity HUB installer found in the DLC resources.

Click on the green Download Unity HUB button (1).

Figure 1.1.2 Unity HUB Download Webpage

Click on this downloaded file to install the Unity HUB program

Accept the License Agreement and select where on your computer the program will be installed (Unity HUB should automatically select the folder it prefers to be installed in)

Finally, click the Install button

Launching Unity HUB

When first launching Unity HUB you, will be greeted by the menu in Figure 1.1.3.

First, click on the icon featuring the outline of the person icon (1) and sign in using the Unity ID you created previously.

Next, click on the license popup message at the bottom of the screen and select Academic/Personal.

Unity HUB is now fully configured; these licensing and sign-in steps should not need to be repeated.

Figure 1.1.3 Unity HUB Launch Screen

This main screen will allow you to start a new project (2) or add an existing project (3).

On this screen select New (1).

Figure 1.1.4 Creating New Unity Project Screen

The New Project screen (Figure 1.1.4) is similar to many popular DAWs such as Logic, Pro Tools, or Ableton.

Unity will ask what you want to name your new project (1) and the location you want to save your project to (2).

For the location (2), you will have to specify a folder to save the project to. Also ensure that the project is set to the default 3D option, as you will only be exploring 3D games development in this book (3).

After setting the project name and save location, press the Create button (4).

I would advise saving your Unity Projects on the fastest drive available on your computer.

It is possible to run Unity Projects from an external hard drive, although the performance may be reduced. This most often happens if the external drive cannot transfer the data while running the game quickly enough to prevent performance issues such as stuttering, low frame rates, or long loading times.

I would also advise NOT saving projects directly within an automatic backup system such as Dropbox™, Google Drive™ or One Drive™. Unity will create, modify, and delete a number of temporary files while working on your project. You may find that as the automatic backup system attempts to delete and restore these temporary files, it could potentially cause corruption in the project, rendering it unusable. I would recommend instead saving your Unity Projects in a regular folder on your computer and copying across a backup of the project if you want to save it in the cloud (rather than attempting to work directly within the cloud itself).

Unity HUB will also save a quick link to a number of recent projects.

Try closing the project you have just created and then using Unity HUB to re-open it.

Figure 1.1.5 Adding and Opening an Existing Unity Project

To open a project, click on the name of the project in the Unity HUB (Figure 1.1.5).

If your project is not visible, press the ADD (1) button and navigate to the Unity Project folder on your computer, then click on the name of the project (2) to open it.

When adding in any of the example projects included in the downloadable resources to the Unity HUB, please note there may be a folder of the same name located inside the Chapter 1 Example Project folder that you uncompressed/unzipped.

You need to select the Chapter 1 Example Project folder located on the one level above the individual project folders.

The image in Figure 1.1.6 was taken on a Windows PC and shows the contents of the individual project folders for reference.

Figure 1.1.6 Unity Project Folder Structure

Trying to open the folder on the incorrect level will result in an error appearing at the bottom of the Unity HUB and the project will not open (Figure 1.1.7).

Figure 1.1.7 Unity HUB Error when Attempting to Add a Unity Project from an Incorrect Folder

When opening any of the Unity Projects downloaded from the additional resources, you may also see the message in Figure 1.1.8. This can appear if you are attempting to open the project using a different operating system than the one last used for the Unity Project and will be likely to appear for those using an Apple OSX operating system.

Figure 1.1.8 Unsupported Build Target Message

If this message in Figure 1.1.8 appears, you should click SwitchTarget. Clicking on the Exit Unity button may still open the project, but you may find that it does not work correctly after opening. If this should occur, the easiest way to solve the problem is to remove the project from the Unity HUB and then re-add it to the Unity HUB and re-open it. This should make the following message appear again, in which case, click SwitchTarget.

Once you have successfully opened the project, this SwitchTarget message will not appear again unless you move the project to a computer with a second different operating system.

If you do not see this message when opening any of the downloaded projects, this is no cause for concern; please skip to the next part of the book.

Unity Panels/windows

Figure 1.2.1 shows the Main Unity Graphical User Interface (GUI). It contains the most commonly used menus, buttons, and Panels. As Unity is used by the entire development team, this includes departments such as Programmers, Animators, Artists, and Game Designers, not only those using it for adding and mixing Game Audio.

To achieve the functionality needed for a variety of different tasks, there are a number of tools, windows, and functions that are specific to each department. This means that, unlike a typical DAW, you do not need to learn every single function to effectively implement interactive audio in Unity. This book will only cover the features required for audio. However, if you want to learn about these additional functions, I would advise starting your research using the online Unity manual https://docs.unity3d.com/2019.4/Documentation/Manual/.

Figure 1.2.1 Unity Main Window

Unity calls the main tabs used for the different areas of the main window Panels.

You can drag and rearrange the position and size of each Panel. I would advise leaving the Panels in their default position when following through the first few chapters in the book. All screenshots have been taken with the Panels in their default position using a single monitor setup. This will allow you to easily follow the provided instructions.

When you have achieved familiarity with the various Unity Panels, arrange these however best suits you, across as many computer monitors as you like.

Project Panel

You will first learn about the Project Panel found in the bottom left of the main Unity window.

Figure 1.2.2 Unity Project Panel

The Project Panel will initially have a single folder called Scenes. Inside of this folder will be a single file called SampleScene.

Figure 1.2.3 Unity Project SampleScene

This SampleScene is the default level file for your new project.

When digital files such as audio, animations, or art textures are added to the project, they will appear in the Project Panel and are now referred to as Assets.

Each file/Asset can be organised into folders, enabling you to find them easily. Creating game-ready Audio Assets will be covered in more detail in Chapters 2 and 3.

The Project Panel is directly linked to the folder structure of the Unity Project, which can be viewed in the Windows Explorer Window or Apple Finder Window.

Figure 1.2.4 Project Folder in Windows Explorer and Unity Assets Folder (Screenshot Taken Using Windows PC)

You can then add additional Assets by either importing them inside Unity or adding them into a folder within the Assets structure in the Apple Finder/Windows Explorer. This process will also be explained fully in Chapter 4.

You can change the view of the Assets using the slider (1) indicated in Figure 1.2.4; moving the slider fully to the left makes the Assets appear smaller and will stack them in a list allowing more assets to be viewed simultaneously.

This change is purely visual/personal preference, but for reference all future screenshots will be taken with this slider in the fully left position.

Scene Panel

Figure 1.2.5 Unity Scene View Panel

One of the most important parts of Unity is the Scene Panel; this is where you build and view the level for the game. This is where you will see any Assets added into the level. Once an Asset has been placed inside of the Scene View, it is referred to as a GameObject. This is simply an object inside the gameworld.

There is an important set of tool icons in the top left of the screen directly under the Main Toolbar Menu (Figure 1.2.6).

Figure 1.2.6 Unity Main Menu Tool Icons

Hand Tool

Move Tool

Rotate Tool

Scale Tool

Rect Tool

Move, Rotate, and Scale Simultaneously

Available Custom Editor Tools

Toggle Tool Handle Position

Toggle Tool Handle Rotation

Toggle Grid Snapping

The first six of these can also be quickly selected using the Q, W, E, R, T, Y keys, corresponding with the numbers just indicated, as a shortcut to speed up workflow when using these Editor functions in Unity.

Hand tool

The Hand tool (1) is used to navigate around the scene. You can change the position you are looking at to move around the scene by holding down the left-click mouse button. This will let you move left, right and up, down when a GameObject is in focus.

You can rotate around the GameObject by holding down the right-click button on the mouse (like when playing most games). You can also zoom in and out of a GameObject by using the scroll wheel/gesture on the mouse.

Move tool

The Move tool (2) is used to move and position GameObjects in the scene. When this is selected, you will see three arrows corresponding to the axis the GameObject will move on: X, Y, and Z.

Figure 1.2.7 Move Tool Axis

The X axis is to move left and right – green/yellow

The Y axis is to move up and down – red

The Z axis is to move front to back – blue

You can place your mouse over an arrow to left click and drag to move the GameObject along that axis, or alternatively left click on the centre of the GameObject where the axes meet to drag and move the GameObject around all three dimensions simultaneously.

Rotate tool

The Rotate tool (3) is used to rotate and position GameObjects 360 degrees. When this is selected, you will see circular lines corresponding to the axis the GameObject will rotate on: X, Y, and Z.

Figure 1.2.8 Rotate Tool Axis

The X axis is to rotate left and right – green/yellow

The Y axis is to rotate sideways – red

The Z axis is to rotate up and down – blue

You can place your mouse over a circle to left click and drag to rotate the GameObject in a fixed location around 360 degrees.

Scale tool

The Scale tool (4) is used to change the size of the selected GameObject in the scene. When this is selected, you will see three arrows corresponding to the axis. The size of the GameObject can be increased or decreased along the X, Y, and Z axes.

Figure 1.2.9 Scale Tool Axis

The X axis is to change the width of the GameObject – red

The Y axis is to change the height of the GameObject – yellow/green

The Z axis is to change the depth of the GameObject – blue

You can place your mouse over a coloured arrow to again left-click hold and drag to change the GameObject length along that axis.

Rect tool

The Rect tool (5) is used to position GameObjects on a 2D plane along the X and Y axes.

One use for this is Pause Menus or Heads Up Display (HUD) icons such as health or score.

Move, Rotate, and Scale simultaneously

The Multitool (6) is a button that will activate the Transform, Rotate, and Scale functions simultaneously, allowing you to move, rotate, and scale GameObjects.

(I would advise you not to use this as it can behave quite unpredictably by changing multiple parameters simultaneously. It can make positioning GameObjects much more difficult than adjusting one axis at a time.)

Available Custom Editor Tools

The Available Custom Editor Tools button (7) is an optional button that can be configured by a programmer to allow various custom functions.

(This button can be ignored as you will not be using any custom tools in any projects associated with this book. When you work on a professional game within a development team, the programmers will explain the bespoke functions they have added to this button, if it is used.)

Toggle tool handle position, toggle tool handle rotation, toggle grid snapping

These Tools (8), (9) and (10) change how the selection of various items in the Scene panel function. I would advise leaving these in their default settings as shown in Figure 1.2.6.

Scene View Camera

The Scene View Camera in the top right of the Scene View can also be used to quickly re-align the Camera to side on or top-down view. This is very useful when trying to place GameObjects with accuracy in relation to one another.

Figure 1.2.10 Scene View Camera

The small lock icon in the top right-hand corner of this image will lock the current Scene View rotation.

If you left click on the <-Persp button, this will toggle between Perspective (Persp) and Isometric (Iso) views.

I strongly recommend using the Perspective (<-Persp) view.

Please also bear in mind the axis for the GameObjects may appear to be pointing in the ‘wrong’ direction depending upon your current view orientation when looking at the Scene or GameObject.

The Scene View Camera takes into account your current view angle and rotation in the Scene.

If you move or rotate your view in the Scene, you will see this model move around, showing you where each GameObjects Axis is currently positioned according to your view in both the axis name and corresponding colour. In practice, this is very quick and easy to adapt to as you normally position GameObjects visually, looking at them relative to other GameObjects within the level rather than relying solely upon the Scene View Camera.

Scene View buttons

The Scene View Panel also has a number of icons in the top left of the Panel.

Figure 1.2.11 Scene View Buttons (Left-Hand Side)

Toggle 2D view on and off

Toggle Lighting on and off

Toggle Audio Preview on and off

Toggle VFX on and off

Toggle Hidden Objects

Toggle Grid on and off

The 2D button (1) will switch the view into two dimensions and make the level appear flat. One use for this is when working on 2D menus such as the Pause menu. If you find you are unable to move closer or further away when in the Scene Level Editor, then check that this button is not active/is unlit.

When the button is lit up, as in Figure 1.2.11 picture for (2), (4), (5), and (6), then it is active.

The function most important to learn is Toggle Audio Preview On and Off (3). This is useful if you want to quickly check how sound sources placed in the scene will behave as the camera moves around the scene.

When this is active, you will be able to hear these sounds as you move around the scene without having to run/play the game.

Buttons (2) and (4), when not active, will temporarily disable the lighting and Visual Effects (VFX) in the game level when viewing the Scene Panel. If your computer is struggling to smoothly run the Level Editor, disabling these options will provide a small boost in performance.

Buttons (5) and (6) will show or hide any objects that are hidden and display a grid; the grid can be useful when attempting to line up two GameObjects together.

The Scene View Panel also has a number of additional buttons and parameters on the right-hand side.

Figure 1.2.12 Scene View Buttons (Right-Hand Side)

Hide/Show Custom Editor Components (spanner and pencil tool)

Settings for Scene View Camera (camera tool)

Toggle to make Gizmos Visible or Invisible

Scene Search Filter

The Spanner and Pencil tool (1) is used for showing or hiding Custom Editor Components.

You can leave this setting disabled/inactivated as Custom Editor Components can be used to change the default behaviour of Unity. All examples in this book use Unity’s default behaviour and so will not require this.

The Camera tool (2) will allow you to adjust the angle of view and speed of the Scene View Camera. I would advise leaving these on the default settings, at least until you have become familiar with Unity.

The Gizmo tool (3) relates to icons such as the Sun and Camera icons in the example picture. I would advise you to also leave this activated, as there are several audio Gizmos that are useful to see in the Scene View. These will be covered in later chapters.

In the top right of the Scene View Panel, you will find a Search Filter (4).

If you know the name of a GameObject you would like to search for (which comes in very handy when giving GameObjects descriptive, sensible names), this search bar can be used to find them quickly and easily. You will notice when searching that all unselected GameObjects will appear greyed out in the Scene View, allowing you to spot the GameObject searched for much more easily.

I would advise leaving all of these buttons in their default settings as these will correspond with the screenshots taken throughout this book unless otherwise stated.

Hierarchy Panel

The Hierarchy Panel will store the list of all the GameObjects as used in the Scene View Panel.

It is basically a list of everything that is added in your current Scene. A Scene file is a level in a game and where you will put together the audio environment for a specific level.

Figure 1.2.13 Hierarchy Panel

Not only does the Hierarchy list everything used in the level, it also handles the Parent/Child relationship between the GameObjects.

So, what is a Parent/Child relationship?

Thinking about this in audio terms, it is a bit like using Auxiliary channels in a DAW when mixing a music track. In Figure 1.2.14, there is a Drums Auxiliary containing individual drum mics, including a Kick, Snare, OH L, OH R.

The signal flow can be thought of as individual tracks routed into a specific Auxiliary fader. The Auxiliary fader is then routed into the Master Fader before going to the speakers or headphones.

If you were to mute the Drum Auxiliary fader on the mixer, even though you still have the individual audio tracks playing, you would not expect to hear any of the drums.

If you changed the volume for the drums using the Master fader, or changed the pan position, you would expect to hear the entire drum kit increase or decrease in volume, and for the panning to move accordingly around the stereo field.

You would also expect to still be able to adjust the individual levels of the kick drum or snare using the individual track faders on the mixer.

Figure 1.2.14 Drum Auxiliary/Master Structure

The signal flow for the GameObjects in Unity uses a similar principle called the Parent/Child relationship.

The drum audio tracks can be thought of as Child GameObjects, as their signal flow requires a path from the individual audio tracks (Overhead Left, Kick, Snare, Overhead Right), to the Drums Auxiliary Master and then finally through the Master Fader.

Figure 1.2.15 Unity Parent/Child GameObject Structure in Scene View

You can view this example project yourself if you download and uncompress/unzip the Chapter 1 Example Project available in the accompanying DLC additional resources.

Use the Add Project button on the Unity HUB program to select the folder named Chapter 1 Example Project.
 (Check you are not accidentally selecting a folder one level up from the project.)

Click on the Chapter 1 Example Project name in the Unity HUB to open the project.

When the project has loaded, finally double left click to open the 1. Parent/ Child Relationship Example Scene.

Figure 1.2.16 Unity Parent/Child GameObject Structure in Hierarchy

If you think of this again as audio signal flow, using the example image in Figure 1.2.16, if an audio Child GameObject such as ‘Kick Drum’ is turned on by default but the Parent ‘Drums Auxiliary Master’ GameObject is off, you can set up scenarios whereby Unity will turn a Parent GameObject on at an appropriate time. This will then allow the Child GameObject to play audio. Alternatively, you can also think of this as a bit like automation in a song to change a track from Unmuted to Muted or plugin from bypassed to active.

One use of this for the audio in a game is that if you had a GameObject containing the VFX for an explosion, you could set your audio as a Child GameObject to play automatically as soon the Parent VFX GameObject has become Enabled. The Parent Explosion GameObject would be turned off by default when starting to play the game; a Game Designer would program Unity to Enable or turn this Explosion GameObject on whenever it is required.

This would then automatically play the audio at the correct time and, equally important, from the correct position in the 3D gameworld.

You can tell if a GameObject has been turned off or Disabled in the Hierarchy, as the GameObject name will be slightly greyed out (1). The checkbox in the Inspector Panel will also be empty (2).

Figure 1.2.17 Unity GameObject Disabled

If a GameObject is Enabled, the name will be solid black (3).

Also when a GameObject is Enabled, the checkbox in the Inspector Panel will have a tick icon (4).

Figure 1.2.18 Unity GameObject Enabled

You can make a GameObject the Child of a Parent GameObject by left clicking and dragging it into the Hierarchy view and releasing the left click to drop it under the Parent GameObject. This will then create a drop-down menu with the Parent and Child Items. You can stack as many Child GameObjects as you like under a Parent GameObject. You can update or remove Parent/Child relationships by left clicking on the GameObject, holding down, and then dragging and dropping the Child GameObject onto any point in the Hierarchy. Have a look at the 1. Parent/Child Relationship Example and 2. Explosion Example Scenes for yourself.

Left click on the Play button in Unity to activate/Play the current Scene and experiment with moving, Enabling and Disabling the GameObjects within the 1. Parent/Child Relationship Example GameObjects Scene.

Figure 1.2.19 Unity Play Button

Make sure you are listening to your speakers or headphones to also hear the examples!

The Play button looks similar to most Transport controls found within audio software. It is the leftmost triangular shaped icon shown in Figure 1.2.19 and can be found in the middle near the top of the Unity window. When you are finished experimenting, if you want to stop Unity playing, left click on this triangular Play icon again.

In Unity, another of the main advantages of using a Parent/Child relationship on GameObjects is that if you create a Parent/Child relationship with multiple GameObjects, then moving the Parent GameObject will also move the Child GameObject in relation to it.

This feature is actually much more important and useful than it may initially appear. One simple example is that you could make a sound for a moving spaceship and place this as a Child GameObject within the Parent spaceship GameObject. Now, when the Game Designer or animator makes the spaceship move around the level, the sound will automatically pan correctly and get louder or quieter the closer or further away it is from the screen.

You can have a listen to this yourself by opening and playing the 3. Spaceship Example Unity Scene contained within the DLC Example Project for Chapter 1.

You can single left click on the name of a GameObject to select it in the Hierarchy Panel

You can double left click on the GameObject name in the Hierarchy to make Unity automatically find, zoom into, and focus on the GameObject in the scene.

(This is very useful when you have a large scene full of hundreds or thousands of GameObjects and you are not sure where exactly it is within the level).

You can rename GameObjects in the Hierarchy by right clicking on it and selecting Rename or by pressing the F2 on PC or the Return key on OSX. It is very important to name each GameObject, as even a small game level will contain thousands of GameObjects. If proper naming conventions are not adhered to, this can make it very difficult to find a specific GameObject later on in the development cycle, as the project or level grows in complexity. It is also considered good working practice when working on a professional game with a number of different developers, as everyone is able to see what each GameObject is for or can search for it simply by reading or using the GameObject name.

Game View

The Game View will show you the game from the perspective of the active camera in the Scene.

When running the game, this Panel will be what the player (and yourself) sees when actually playing the game.

It can sometimes help to see the Scene View and the Game View from the same angle when positioning GameObjects in the gameworld. You can quickly and easily align the Game View camera to the current Scene View by having your Main Camera GameObject highlighted in the Hierarchy Panel and then using the GameObject menu at the top of the screen selecting Align With View.

Figure 1.2.20 GameObject Menu Align with View

The Game View tab has several parameters buttons to configure various settings.

Figure 1.2.21 Game View Buttons

Display View – Allows you to pick from available Game Cameras (leave this set to Display 1)

Aspect Ratio – Set this to 16:9 to match most consumer TV/computer screens

Scale – Enables zoomed in view (leave this slider fully to the left – 1x)

Maximise On Play – Enables Game Panel to go full-screen when playtesting game

Mute Audio – Mutes all audio when the game is playing (make sure this is NOT enabled!)

Stats – Enable overlay, including information on current volume in decibels (dBs)

Gizmos – If enabled, will allow Gizmo icons such as Camera to be visible in the Game View

Inspector Panel

The Inspector Panel is context sensitive. This means it will show you information about various GameObjects you have selected in the Project Panel, Scene View, or Hierarchy. The parameters shown will change depending upon what type of GameObject has been selected, such as an AudioClip, Texture, or Script. These will be explored individually and in more detail through various later chapters.

Figure 1.2.22 Inspector Panel

The parameters of the Transform Component show where the GameObject has been positioned in the 3D world. All GameObjects placed in the 3D world will require a Transform Component to tell the game engine where the GameObject is placed.

The Position, Rotation, and Scale will directly correspond to the Move, Rotation, and Scale Icons covered previously. You are able to click on any of the X, Y, or Z values and type in a new value. In certain scenarios, this can be a quick way of aligning GameObjects to one another across a large level/Scene.

Figure 1.2.23 Transform Component

Additional Unity functions

Saving the Scene

Save your Unity scene often to avoid accidentally losing any work. You can do this by left clicking on the File Menu near the top and selecting Save to save the current Scene. DO NOT select ‘Save As’, this will save your current Scene as a new Scene file. In a project featuring multiple Scenes or levels, these are often coded to transition from one to another.

Save As will create a new file that is NOT automatically integrated into this system.

Figure 1.3.1 Saving the Scene Using the Save Button

You can also use the shortcut Ctrl + S on PC or CMD + S on OSX.

Instant feedback

One of the main advantages of Unity is that it allows you to make changes and then test the changes in your game straight away.

Why is this a good thing?

In some other game engines, the user will have to instruct the game to make a build (a playable version of the game) every time they want to hear or see any changes they have made. This can be quite time consuming as it may take between 5 and 10 minutes (depending upon how fast your computer is and how big the game is) between iterations to test any changes you have made. As Unity does not require you to wait when making a build to test changes, it enables you to work very quickly to try out new ideas.

Changing background colour of Unity Editor

You can also change the colour or theme of the background in Unity if you find the default colour too bright and wish to use ‘Dark Mode’.

Click on the Edit Menu found along the top of Unity and select Preferences.

The Preferences Panel will pop up; using the General tab, you can change the theme/colour of Unity and select between Light and Dark Mode by left clicking on the current name. When finished, left click on the ‘X’ icon to close the Panel.

Figure 1.3.2 Editor Background Colour

For reference, all screenshots in the book will be taken using Light Mode; however, they will correspond exactly with Dark Mode if you choose to use this.

Panel layout

Another helpful feature in Unity is that you can arrange and resize the Panels any way you want. There is no right or wrong way to arrange these; it is purely personal preference.

You can save several Panel Layouts of Unity as presets and switch between them whenever you want.

You may find switching between different Layout Views useful when you start looking at other areas of the game engine. You will start working on specific Panels, as this can be a handy way to save time.

You can click and drag to move your Panels around the window and resize them to suit your current needs. You can save or load a Panel Layout by clicking on the Window menu at the top of the screen, selecting Layouts and then saving or loading a layout configuration.

If you accidentally close or move a panel and wish to reset the Panel Layout as used in this book, select the Default layout.

Figure 1.3.3 Window/Panel Layouts

You can also right click on any Panel to maximise it or Close Tab to remove it from your view.

Figure 1.3.4 Maximize or Close Panel

If you want to see a Panel again after closing it, click on the Window menu along the top of the screen, select the General tab, and left click once on the panel you would like to view to return it to your main Window.

Figure 1.3.5 Panels and Shortcuts

From this point on, I will refer to the Inspector Panel as the Inspector, the Hierarchy Panel as the Hierarchy, the Scene Panel as the Scene View, and the Game Panel as the Game View.

This shorthand more closely resembles the terminology you are likely to hear when working in a real development studio or when reading online forums or viewing YouTube ‘How To’ videos.

5 quick tips

Remember to save your project often to avoid losing work if Unity crashes.

When modifying any value in the Inspector Panel, if you do not see the change you are expecting, check you have not accidentally left the Inspector locked and are inadvertently modifying a different GameObject.

You can prefix your own Custom Layout names with a $ sign to make them appear at the top of the list as shown in the previous image.

Unity has a number of shortcuts for many of the functions explained in this chapter and throughout the rest of the book. You can view the list of shortcuts and, if you want, modify or change the keyboard bindings used by going to the EDIT Window menu and selecting Shortcuts.

You can view the Unity manual by going to the Help Menu and selecting Unity Manual.
 This will let you view additional information about all sections of the Unity game engine.

Chapter 1 practical task

The practical task for Chapter 1 is to get some hands-on experience with Unity, using the skills you have learned to create a new project and build a simple model using 3D GameObjects in Unity. This is good practice for being able to accurately place audio inside the game during Chapter 3’s practical task.

You may find that if you have not used any 3D software programs previously, lining GameObjects up and placing them correctly can take some practice. When teaching Unity to Music Production/Sound Engineering students, I have found that for the majority of people, practicing this for an hour or two is usually sufficient to understand how these GameObjects move and to position them where you intend them to be placed in 3D within the gameworld/Scene View Panel. If this takes you a little, longer don’t worry; spend some extra time and with practice you’ll pick it up.

Feel free to download the Chapter 1 Example Project featuring a model of a drum kit and add to this scene if you want to make a model of a mic stand, amp, guitar, or whatever else you want. If you want to start from a blank canvas and make something completely different, that’s also no problem; start your first brand new Unity Project and make something from scratch.

Aesthetics and accuracy of the models are not the primary concern; instead, please focus on practicing using the various Panels, Tools, Parent/Child relationships between the GameObjects, and naming conventions covered previously.

To add in a 3D GameObject, right click in the Hierarchy Panel, hover the mouse over 3D Object, and then left click on either the Cube, Sphere, Capsule, or Cylinder to create the GameObject in the Scene View Panel.

You can then use these simple shapes and modify these further using the Transform, Rotate, and Scale tools to construct your basic model.

Figure 1.4.1 Creating 3D GameObjects

Figure 1.4.2 Completed Example Including Parent/Child Hierarchy Organisation

After lining your GameObjects up, look at the model from different camera angles in the Scene view to make sure the GameObjects are actually lined up correctly. Sometimes two GameObjects may look lined up for a single camera perspective, but when looking around from various sides and above or below, you may find that the GameObject is not actually where you think it is.

You can have a look for yourself using the Practical Task Drumkit Example Scene found in the accompanying DLC Chapter 1 Example Project.

2 Game Audio Sound Design and creation

DOI: 10.4324/9781003055167-2

Many industry professionals would agree that the overall audio experience of a game is split fairly evenly between the actual audio files the game engine plays, which are commonly referred to as Audio Assets, and the implementation, i.e. how the game engine interactively plays the audio.

50% – Assets

50% – Implementation

This chapter will introduce you to and outline the unique requirements associated with Game Audio. It will also delve into a number of theoretical approaches to sound design methods using real world examples from notable games and films. The concepts discussed in this chapter will help you when making creative choices and applying them practically to your own sound design in the following chapters.

I’m not so self-centered that I would ever attempt to summarize ‘what sound design is about’ in just a few words, but I can certainly tell you what it’s NOT about. Sound design is NOT about plugins, it’s NOT about which DAW you use, it’s NOT about which headphones you buy, the same way cooking is not about which brand of whisk you use.

When you begin as a Sound Designer, the desire to feel as though you’re making fast progress can be temporarily satiated by buying a flashy new tool or upgrading your hardware. That sensation of ‘instant improvement’ is not real. Even worse, if you chase that feeling for too long, that feeling of excitement will be replaced with intimidation, and opening a new blank audio session will start to feel embarrassing … 50 unused plugins will stare at you from your computer screen as if to say

‘Well? What’cha got today punk???’

Don’t put pressure on yourself to be good right away. It’s alright to feel as though you can’t make what you’re hearing in your head! Every Sound Designer I have ever worked with or looked up to still feels that way from time to time, and chances are good that I’m feeling that way as you read this right now.

If you can harness that feeling of frustration and instead redirect it towards fun, experimental, joyful methods of making sounds with no real expectation that the results will be ‘up to industry standards’. You’ll slowly develop a connection with your ears that will later down the line become your own inimitable style.

Marshall McGee
(Sound Designer, People Can Fly Studios, Avalanche Studios), Creator, Waveform YouTube Channel, www.youtube.com/c/MarshallMcGee

Sound design introduction

People use three main senses when playing video games: sight, sound, and touch. A lot of the subtlety in sound design may not be immediately apparent to the average game player. The average gamer tends to focus on visuals and will often be more vocal and able to point to specific problems they are able to see in a game. Quite often, if there is something in the audio of a game that is not correct, most players won’t know exactly what is wrong with the audio, just that something is ‘bad’. It is your job as a Sound Designer to be able to listen critically to the sound of the game throughout the sound design, implementation, and mixing process, to ensure that the audio will reinforce the story and narrative, deliver information to the player, and enhance the overall game playing experience.

Sound is essential to creating believability. It provides feedback for action both on and off screen, manipulating emotional responses. Often this is without the player/viewer actively becoming aware of its influence. Audio helps to guide player actions and shape their experiences as a whole.

Believability means that the game player is able to fully believe that what they are hearing is representing what they can see in the game. Have you ever been so focused when playing a game that it consumes you? You become less aware of your surroundings, lose track of time, and focus 100% of your attention on the game and are ‘in the zone’.

This is called Total Immersion and is one of the most enjoyable experiences you can have while gaming. The preceding is a very brief explanation of this as entire books and research papers have been written to more fully explore this phenomenon. As powerful as Total Immersion can be, it can be broken very easily, snapping you back to reality. This can be caused by something as simple as hearing a distracting notification on your mobile phone or someone calling your name from across the room. Total Immersion can also be broken from a gaming perspective. For example, if a sound does not accurately reflect the visuals, such as playing the wrong footstep sound for the surface the playable character is walking across, or if dialogue does not accurately reflect what has just happened in the game.

Throughout your life, your ears have constantly informed you about the world around you, from how large an object may be based upon its volume or frequencies, to the size of a room based upon the reverb characteristics. When playing games your ears still function in this same way. Often, Game Audio will attempt to imitate many of these natural phenomena; accidentally making a sound that doesn’t fit the visuals on screen, or even is mixed vastly different to what you may expect to hear in the real world, can instantly break that immersion as it does not sound ‘believable’.

In addition, if the sounds become too repetitive, aside from this sounding annoying to players, the brain can begin to subconsciously tune it out. Your job as a Game Sound Designer is to create an adaptive and responsive audio experience that will enable the player to achieve Total Immersion and maintain it for as long as possible.

Diegetic/Non-Diegetic

In a game, if you are able to see an explosion, you would expect to also hear an explosion SFX to go with the visuals. This type of sound is called Diegetic because there is a visible source on the screen that the sound represents. In most cases for diegetic sound, you will be attempting to make sounds that correlate with the visuals, and then to mix these to sound like they are panned from the correct place on screen and at an appropriate volume.

Non-Diegetic is categorised as audio that does not come from a visible place in the gameworld. A primary example of this is background music; when playing a First-Person Shooter (FPS) game you often hear background music, but if you look around the level you won’t find an orchestra or band following you around as you play. Non-diegetic audio can also be used very creatively when making all of your ambient atmospheric SFX, to make the game level feel much more alive than what is shown visually on screen. For example, if the game was based in a jungle, you could have the sounds of bushes rustling and animal calls just outside of the player’s line of sight to make the ambience much more immersive for the player.

Creating emotional responses

You can use audio very effectively to manipulate the player’s emotional responses. One of the most effective examples of this is from the movie Jaws (1975). I’ll bet that you are able to hear the famous ‘dun, dun’ two note repeating riff in your head right now. What actually makes this piece of music so effective is that the composer, John Williams, uses it throughout the movie every time you see a shark fin in the water. He teaches the viewer to expect to see the shark when hearing this piece of music.

What makes the final jump-scare shark attack such a surprise is that this is the only time in the movie in which the two note ‘dun, dun’ riff is not heard before seeing the shark. This is only one example of how Sound Designers can use a very simple but effective audio trick to have a massive impact upon the player’s emotional response. Sometimes not playing any audio can be more effective than adding SFX or music into every single event and area of the game. Knowing when and how to use audio is a skill that you will gain over time by critically analysing the audio for any games you are playing or TV shows/films that you watch.

Priorities

Next time you are playing a game, really listen to everything, rather than just hearing it. Listen to how individual sounds are using which parts of the frequency range, how loud they have been mixed, and if the sounds change interactively based upon events or actions you take in the game. After performing critical analysis on the games you play yourself, you will develop a knowledge base of experience and references to help you make creative decisions when working on your own Game Audio projects.

You will soon find that different genres of video games have different priorities when it comes to audio.

In strategy games such as the Starcraft, World of Warcraft, and Total War series, a common defining characteristic is that notification sounds are short and easily recognisable, which is essential in alerting players to events in the game such as fighting or that new upgrades and units are now available.

In racing games such as the Dirt and F1 series, it is of utmost importance that the cars sound as authentic, realistic, and responsive as possible. The engine sounds need to respond to acceleration and deceleration; you need to be able to hear the difference in every surface the car drives over, and if you crash, the impact sound needs to be appropriate for the force of the collision.

In competitive FPS games such as the Call of Duty or Battlefield series, the localisation of the sounds should be able to tell you how far away the other players are, roughly what direction they are from you, and what kind of gun they are using. You would expect when playing games such as these that a sniper rifle will sound very different from a pistol, a shotgun, or a futuristic plasma rifle. In competitive multiplayer FPS games, being able to understand the information that the localisation of the audio is providing will offer a very real strategic advantage against other players, such as being able to tell roughly what direction and how far away they are based solely from the audio.

Audio is absolutely crucial for video games of all genres; it can be used in a number of ways beyond just adding in sounds to accompany the things the player is able to see within the game. As consoles and computers continue increasing in power, developers and players feed off one another by continually pushing the boundaries of what is possible to achieve visually and aurally in games. As the bar is continually raised, the tools and techniques that were on the cutting edge a few years ago, quickly become accepted as the minimum quality benchmark for new AAA releases.

How Game Audio differs from post-production

You may have some previous experience with overlaying sound to a video that you’ve uploaded to your YouTube channel or even taking existing gameplay or movie clips, muting all of the original sounds, and re-imagining and creating your own sounds and mixing/overlaying these onto the video clip in your DAW. This process is broadly known as Audio Post-Production and there are skills that will transfer over to Game Audio. If you’ve never tried any form of sound for moving picture before, then don’t worry; you can develop these transferable skills while working on the practical projects included with the downloadable resources that accompany this book.

Film and TV shows are linear

The fundamental difference between Game Audio and post-production is that TV/movies are linear.

Linear means progressing from one stage to another in a set and pre-determined series of steps from beginning to end. This can also be described as using a fixed sequence of events or as sequential. For example, in your favourite movie, if an explosion happens 30 seconds into the movie, when re-watching the movie, the explosion will always happen at the same time shown from the same camera angle and will always sound the same.

Figure 2.2.1 Linear

Games by definition are non-linear and interactive

This provides a completely different set of challenges when compared with TV and film sound. The audio in interactive games needs to change and reflect the player’s actions and choices in gameplay. This means that the player controls to a large extent what events happen, how they happen, and when they happen.

Figure 2.2.2 Non-Linear

Video games can offer players a variety of choices. Even simple 2D platformers such as Super Mario Bros (1985) allow the player to choose when to move, when to jump. These player decisions then cause the jump sound to play and affect the events and audio playback in the game. Games have increasingly allowed the player greater freedom and choice as they have progressed through the years, including additions such as choosing between various dialogue options in the Skyrim or Fallout series, to entirely changing the story outcomes in narrative games such as Heavy Rain (2010) or Telltale’s The Walking Dead (2012). In stealth games such as the Metal Gear Solid or Hitman series, the player can also choose their gameplay style. The player may attempt to sneak around unnoticed or just go in all guns blazing. Quite often when attempting to play stealthily, due to the gamer’s own actions and choices, they could be spotted by an enemy or trigger an alarm at any point in the gameplay. When sneaking around, the ambient sounds will often be detailed and allow for lots of precise localisation of sound sources to help the player know where the enemies are, how many of them are there, and if they have been alerted to the player’s presence yet. After the playable character is spotted by an enemy or triggers an alarm, the ambient sounds will usually become less important as the enemies will normally begin shooting loud guns. At this point, the music will also change and become more intense and potentially louder, forcing a sense of urgency onto the player. The primary goal of a great Game Sound Designer should be to recognise what the Game Designer is attempting to achieve and then support, exaggerate, and enhance this vision using audio. When next playing a game, pay attention to the audio. Try to assess how it is being used to support the gameplay, what sounds have priority in the mix, or are most important at the current time; if you perform actions to trigger events in the game, does the priority change and if so, how?

The biggest challenge with Game Audio

When creating audio for linear media such as film or TV, the Audio Engineer is in complete control over where they will place sounds and how they will mix them, using tools such as automation in a DAW. They can also quickly hear any individual changes to a mix or when designing sound in relation to the whole mix. To a certain extent when working on audio in a DAW, they don’t have to worry about balancing resources on a computer. This includes resource limitations, such as how many simultaneous audio tracks are currently in a project or how many plugins are being used. A computer dedicated to mixing audio has the entire processing power available for a single audio application or program, compared with a video game designed to run on a less powerful console or mobile phone. The biggest difference in workflow is that when working in linear media, the Sound Designer knows that the exact order of events on the timeline will always play back in exactly the same way.

Game Audio is much more challenging in certain respects because each person will play the game differently. Another challenge is that the interactive mix is limited to a certain extent by the Playback device, commonly referred to as the hardware that the interactive game will be played on. More powerful consoles and PC hardware are capable of playing back more sounds at once using higher quality audio processing. The next challenge is that the End User or Player is, to a large extent, responsible for triggering these events at any time using any combination of actions the game allows them to perform. When creating audio for a game, you have to be aware of how all these actions can impact the final audio experience throughout the whole development process, from creating individual Audio Assets to the final mix. The most important and defining characteristics of a video game is interactivity. Although a Game Developer can set the location, objectives, and rules for the player’s movements and actions, they are ultimately giving up final control over the pace, focus, and depth of the story to the player.

Sound design considerations

Games, unlike typical linear media such as TV or film, have a number of considerations that must be taken into account when creating and designing the sounds, to make sure that they play appropriately and creatively in all gameplay scenarios.

One Shot and Loops

A One Shot is a singular Audio Asset, an audio file that is designed to be played back to correspond with a single action such as a footstep or a grenade explosion.

A Loop is a looping Audio Asset that is designed to play continuously over and over again from beginning to end. When creating loops for use in games, as with music editing, you will aim to make the Loop Point where the file transitions from the end, back to the beginning, seamless. When listening to this audio file continually playing back or ‘looping’, you should not be able to hear where this Loop Point is within the file when listening to continuous playback. Two examples of where loops are used in Game Audio include music and non-diegetic ambience.

Chapter 3 will offer some specific practical editing technique to create One Shots and Loops specifically for use in a game engine.

Creating sounds in isolation

When creating sound for games, an added challenge is that Audio Assets are usually created in isolation. In typical audio post-production for a TV show or movie, a Sound Editor is able to hear what they have created so far and listen to exactly how each new element will sound when added to the piece as a whole within their DAW. In video games production, you do not have this privilege. Sound Designers tend to create the sounds individually in a DAW and then add them into Unity to implement and mix one by one. It is imperative that you consider how individual sounds will fit into the bigger concept of your game while creating them in isolation in your DAW.

With great power comes great responsibility

One common mistake Sound Designers make when first starting out designing sounds individually using a DAW is following their natural instinct to make each sound as big, detailed, and exciting as possible. However, you will soon find that if you apply this process to every sound you make, your mix will become cluttered with lots of sounds all competing for the same frequency ranges within the mix. This is known as frequency masking.

Another common issue many people encounter when beginning to develop sound design skills is how they approach making the big, loud, important sounds really have an impact within the mix as a whole.

An initial approach many begin with is to add in lots of additional sound layers to increase the perceived weight and impact in a sound. For example, if you want to make a massive explosion sound, many inexperienced Sound Designers, when working inside their DAW, may just rely on layering multiple similar explosion sound files, lining up the transients to play simultaneously. To increase the perceived weight and power, they often rely on increasing the bass frequencies using an Equaliser (EQ) or a harmonic distortion/saturation plugin.

This issue is more problematic and harder to identify when creating audio for games compared to typical linear audio post-production. These techniques are all very effective and there is no reason not to make use of them, but they should be respected and used within reason, as it’s very easy to continue applying this tactic to all of the big sounds in the game. While these techniques may achieve your aims in the DAW, when listening to the sound by itself you will quickly find that this will oversaturate your mix with too many frequencies all completing for the same sonic space, thus causing the frequency masking issues discussed previously. Overdependence on these approaches and using them on too many of the individual sounds often leads to inexperienced Game Audio Sound Designers then having to add in more and more layers and processing to each subsequent sound, resulting in also mixing these sounds louder and louder to try to create the desired impact. When using this approach, you run the risk of running out of headroom in the mix and being forced to try to make everything sound big; then, when listening to the mix in context, no sound individually stands out, sounds bigger, or has impact when compared in relation to one another.

As can be seen in the example earlier, boosting lower frequencies to add size and weight to a sound can be a very effective solution. However, you also need to consider if the sound will be used in a section of the game that will already have a lot of low frequencies from a source such as an atmospheric ambience track or music. You need to ensure that the sounds you create will work within the mix in every potential place they may be used.

Where does the sound fit within the mix?

It is very important, when designing individual elements such as notification sounds, to be aware of how the sound frequency, detail, and final mix volume will fit into the mix. It is vital that these notification sounds are easily identifiable, particularly when they are so integral to gameplay in Real Time Strategy (RTS) games such as World of Warcraft, Total War, and the Civilisation series. Next time you play a game similar to these examples, if the in-Game Audio settings allow, try making all User Interface (UI) and notification sounds silent or turn the audio off completely to experience how much more difficult the game is to play without the audio providing cues. These could be friendly units coming into contact with an enemy, that a task you have been set by a Non-Player Character (NPC) has now been successfully completed or failed, or that an upgrade or powerup is now available.

It is essential that these sounds are easily recognisable and clearly able to cut through the mix when a lot of loud additional sounds could also be playing at the same time. Next time you play a game that features notification sounds, pay attention to the prominent frequency range that various sounds occupy. You will discover that the majority of notification sounds do not rely heavily on very low or high frequencies for their main content, and that these sounds focus mainly within the 1–4 kHz range, as this is where human hearing is most sensitive.

In my professional experience, I believe it is much easier to start with a mix that lacks certain frequencies and then add elements to fill these out, rather than working on a mix that has considerable frequency masking and then attempting to remove frequencies or sounds to solve this problem.

Quite often when designing sounds, I will use a minimalist approach by removing all unnecessary lower or higher frequencies. I then design each sound to fit into a specific place within the frequency range. When testing the game later in development, after all the major audio elements have been added, it is then much easier to revisit and update certain sounds to increase their frequency range.

Frequency ranges

It is important to be able to recognise the sonic space that each sound will be using and how the balance of frequencies is currently being utilised at various points throughout the game. The following table features the main frequency ranges with a brief description of the effect you will hear when these are under or over represented within the individual sound and the overall mix.

Table 2.2.1 Main frequency ranges

20–60 Hz | Sub Bass: Very low frequencies that will be felt rather than heard from a subwoofer. These should be used sparingly as an accent to larger prominent SFX, such as explosions.
60–250 Hz | Bass: Low frequencies used to add weight to a sound. Excessive use of this frequency will make the sound or mix ‘boomy’; a lack of this will make the sound or mix weak.
250–500 Hz | Low Midrange: Contains lower order harmonics. Excessive use of this frequency range will make sound/mix ‘muddy’; not enough will make the sound/mix lack ‘energy’.
500 Hz–2 kHz | Midrange: Determine how easily individual sounds cut through mix. Excessive use can make the mix ‘tinny’; a lack will make the mix ‘thin’.
2–4 kHz | Upper Midrange: Human hearing is very sensitive in this range. Excessive use can make mix ‘fatiguing’; not enough will make the mix ‘hollow’.
4–6 kHz | Presence: Clarity and definition of higher order harmonics. Excessive use can make a mix or sound ‘harsh’; a lack of this will sound ‘dull’.
6–12 kHz | Top End: The High End or Treble. Excessive use can make a mix sound ‘fizzy’; a lack in this range will sound like ‘detail is missing’.
12–20 kHz | Brilliance: The highest frequencies, like the sub bass, should be used sparingly in certain sounds as an accent to add in ‘sparkle’.

To help learn to recognise these particular frequency ranges, you can use a signal generator or download some pink noise, and in your DAW add an EQ with a steep High Pass and Low Pass cut-off set to these specific ranges. Hearing these frequency ranges in isolation will help train your ear to recognise these within individual sounds and the mix as a whole.

What is the sound going to play back on?

It is also important to also have an understanding of the technical limits for the target medium. Consider the playback devices themselves. If they use built-in speakers, such as the Nintendo Switch™, or mobile phones, as these may not be capable of reproducing the full frequency range. This can mean, on certain handheld devices, making sure that you are not creating Audio Assets that rely on using the extreme low or high regions of the frequency spectrum. Using lots of high frequency content that the device speakers will be unable to reproduce, or lots of sub frequencies, could potentially cause speaker distortion as the device cannot recreate them using their smaller, inbuilt speakers.

When designing for current consoles such as the PS5/Xbox Series X and especially handheld gaming devices such as the Switch or mobile phones, you may have to compress or reduce the data size of your game Assets. To achieve this, it’s not uncommon to reduce the sample rate of audio files to ensure they fit within memory budgets relating to the overall size of the complete game.

In addition, these playback devices have differing capabilities in terms of processing power available for transforming sounds while in-game, with high-end PCs having the largest budget and mobile phones having the least.

To an extent, Unity will handle the volume and panning changes for your sounds automatically, depending upon the playback parameters you have set. It is important to keep in mind, when designing sounds that will be manipulated dynamically and interactively by the player within the game engine, that you need to account for this additional interactive processing within the game engine when first designing the sounds using your DAW. One example could be changing a sound with EQ or pitch while the player is performing a particular action: you will need to keep in mind that your sound will need to work within the mix at all stages of the interactive processing.

How should audio processing be applied?

This often leads into the question: What processing should you apply to your sounds inside the DAW and what processing should be applied by the game engine?

Most audio processing will typically be applied during the sound design process using the effects in your DAW. The advantage of this method is that the Sound Designer is able to apply as much processing as they want to the sound using high quality plugins or outboard gear. The disadvantage to this technique is that the sound may have less interactivity when playing inside the game engine, as the majority of processing has already been applied.

The Borderlands series used interactive processing inside the game engine for the dialogue to solve an issue that is present in many Role Playing Games (RPGs). The player is able to talk to an NPC to start a quest. However, in Borderlands, if the player walks far away from the speaking character, then the voice dialogue will automatically add processing as if through a futuristic walkie talkie device. This allows the player to begin walking away and start the mission whenever they want, while still hearing all of the dialogue. This very clever use of in-game processing means that the player doesn’t have to choose between standing in front of the NPC until they finish speaking or risk leaving to start the quest and missing out on crucial game dialogue. In this case, applying the processing interactively within the game engine enables much more flexibility, as the game can add in the processing at any point during the dialogue if the player walks a set distance away from the NPC.

Reverb can also be applied inside a DAW or from within Unity; this is another creative choice. The advantage to using Unity’s reverb is that all sounds will have cohesion as they are using the same in-game reverb. Additionally, the reverb setting can then also change dynamically in different areas of the game. You would expect the reverb for footsteps to sound different in areas such as a cavernous cave, a bathroom, or a metallic corridor. Using Unity’s in-game reverb means you only need to create a single dry set of footsteps that various reverb parameters can then be applied to interactively, allowing much greater flexibility and reducing the total number of audio files required for the game. That being said, you could also apply reverb directly to sounds or dialogue using a DAW for creative reasons. One reason for applying the reverb using a DAW, rather than inside Unity, could be that you want to use a totally different reverb to help differentiate between or separate specific sounds within the mix. Another could be that you want to have a consistent reverb throughout the game for these sounds, such as Pause Menu beeps and clicks, if you do not want these to be affected or changed depending upon the environment the player happens to be in. This topic will be expanded upon when discussing using reverb within Unity in Chapter 7.

Practical game sound design tips

How to make sounds appear powerful without relying solely on increasing bass, volume, or excessive layering

As discussed on previous pages, when creating Audio Assets in isolation within a DAW, to make a gunshot appear powerful it can be tempting to use an EQ to boost frequencies or to layer different gunshot and explosion sounds on top of one another. By adapting your approach, you can create the result in the game you want without relying solely on just these techniques.

To a certain degree, the ‘blast’ or actual ‘shot’ portion of many guns are actually fairly similar. In essence, the ‘shot’ portion can be broken down to a short blast of filtered white noise. To infuse the gunshot sound with perceived weight and power, one technique is to concentrate not on the firing or blast sound of the gun to sell the idea, but rather on the sounds around the ‘blast’ or ‘shot’ portion of the sound.

The differentiation, character, and perceived weight within the sound comes mainly from the mechanical sounds emanating from the physical mechanisms of the gun. This includes the Foley sounds when racking a shotgun or bolt action rifle, the click of the hammer when pulling the trigger, the shell/case flying out of the gun after firing and landing on the floor, and the reload sounds. In addition to this, you also have the ‘after-shot’ sounds as the bullet whizzes through the air and impacts the target. Making these ancillary sounds bigger by focusing on exaggerating these elements will make the player feel powerful when firing the gun.

Using an additional trick of delaying the layers of the sound can actually have a bigger perceived effect on the final sound than lining all of your transients up to start at the same time. Ensuring the trigger sound is 100–150 ms before the actual blast, and by delaying the midrange sound by 50–75 ms, you get the initial bass energy dispersing into the chest before the higher frequencies of the ‘blast’. All of these tips, alongside with fairly extreme compression, will combine to enhance the perceived effect of the sound for the player, making the gun sound aggressive, weighty, and powerful.

This type of technique described earlier, of enhancing the elements around the ‘main’ sound, can also be applied to other different types of sounds that you want to have weight and power. For example, if you want to create a large, meaty punch sound, instead of focusing solely on the impact of the punch, think about the smaller ancillary sounds you could exaggerate and enhance: heavy, quick moving clothing sounds, the ‘whoosh’ of the arm moving before the impact and the ‘crunch’ of bone and ‘splatter’ of blood just after the initial impact. The punch sound also lends itself to using variable delays between the layers of the sound for the bass and midrange sounds of the punch impact, much like the gun-firing example.

The final tip, and one of the most important, is that when recording your own source material, if you intend the sound to be used in a bass-heavy, weighty sound, then take advantage of the proximity effect. The proximity effect is the natural increase in bass or low frequency response when a directional or cardioid microphone such as a Shure SM57 or SM58 is positioned close to a sound source. No matter how good your EQ is, it cannot boost frequencies that are just not present in the sound to begin with.

The sound design techniques discussed in this chapter are not just applicable to the examples used; many of these techniques can be just as effective when used on a variety of sound sources.

Ensuring consistency between sounds

One option when planning how the sound design for a project should best support the artistic style is that you may decide all the audio should also follow a stylised theme. An example of this may be to process all of the sounds using the same plugin processing chain.

This technique was effectively used in the platformer game LIMBO (2010). The Sound Designer, Martin Stig Andersen, ran all of the SFX for the game through a cassette player and re-recorded these using the cassette player as if it were a piece of outboard gear. The natural characteristics of the tape recorder fitted with the visual theme of the game and imparted a sonic characteristic of slight compression, adding noise and reducing higher frequencies. This same processing, applied on all sounds, helped give the individual SFX cohesion. He used a similar technique on another game called INSIDE (2016), where he ran all of the Audio Assets through a human skull and jawbone, re-recording them with a contact microphone. This again added a certain resonance to specific frequencies and helped cohesively bind all of the sound Assets together.

This concept of using a similar processing chain does not have to be applied to every sound in the game. It is just as effective to use a similar plugin chain or style of processing to help give cohesion when applied to all of the sounds for a particular character or enemy in the game. For example, you could use granular processing plugins to process/synthesis all of the sounds for one specific character, and time-based effects such as delays, phasers, and chorus on another, different character. This will mean that all the individual sounds needed for each character will sound similar, but that each character will sound unique and different from one another.

This particular technique can be just as effective on a per sound basis, to help fuse different sound recording elements together when designing individual sounds. I often find that when doing sound design, I may use different recorded samples that sonically are very different from one another. While the sound overall may achieve the desired goal, the layers within that sound may not initially blend together very well. In this case, I will often apply a type of harmonic-based processing, such as subtle distortion directly to the master bus; this helps to give all of the layers in the sound a similar tonality.

This technique can be applied to all sounds equally, or used like the Parallel Processing music mixing technique, blending a portion of the processed sounds back into the original using an Auxiliary to balance the wet/processed and dry/unprocessed sound.

Using sound to encourage or discourage

Sound is able to influence or reinforce a player’s response, such as happy/sad or positive/negative.

Examples of positive reinforcement are the coin collect sound used by Nintendo in the Mario game series or the stud pickup sound used in the LEGO video games series. These sounds are very musical and playful; they’ve been specifically designed to make the player feel happiness or joy when the sound is played as it corresponds to increasing their score. Mobile games especially try to use sound to positively reinforce the player when they achieve a goal or task in the game. Sound is used to reward the player and encourage them to keep playing and completing more tasks. This type of sound design is particularly applicable to mobile games such as Pokémon Go (2016) and Clash of Clans (2012), and also includes games that use sound as a way of rewarding the player when they achieve a new level rank, unlock a collectable, or buy an item.

The concept of using sound to influence player actions is not new or unique to video games. Casinos and slot machine manufacturers are aware of the power of sound to attract new players and influence current players to continue playing. If you won on a slot machine, bells, alarms, and various loud sounds would begin to play. These sounds are not just for the benefit of the person who has won; they also serve to encourage other nearby players to believe that they might also be close to a win, thus influencing them to continue spending money.

TV game shows also use sound to help communicate information to the players and the audience. There is usually a ‘chime’ type SFX if the contestant answers correctly or a ‘buzzer’ type SFX if they answer incorrectly. The chime is an example of positive reinforcement and the buzzer is an example of negative reinforcement.

Another example of negative reinforcement is when playing a shooting game such as Call of Duty or DOOM series. If the playable character becomes injured, it is typical that their view on the screen will be restricted along with a heartbeat sound that will begin playing. This heartbeat sound usually also reduces all other sounds at this point in the game. By obscuring the typical audio mix and restricting the player’s view, this makes it harder for the player to continue playing as normal and encourages them to seek cover to regenerate their health.

A perfect example of positive and negative reinforcement used in many games is a beeping SFX for a radar system. By changing the pitch of the beep you can easily inform players if they are getting closer or further away from the target without relying solely on visuals.

Creative applications of sound

Sound is immensely powerful in building atmosphere and manipulating the player’s emotions. One genre that relies heavily upon sound for this is horror. You will notice it in games such as the Resident Evil, Alien Isolation, or Dead Space series. Sound can often be used to create the impression that the gameworld is much bigger, busier, or more interactive than the player is able to see.

One example of this could be if the player is tasked with walking down a long, dimly lit corridor. As the player is unable to see very far in the distance, Sound Designers can take creative license to increase the tension and atmosphere. One approach may be to increase the density of atmospheric SFX by playing random bangs, creaks, or monster noises to make it sound as if there is something stalking the player just on the other side of the corridor or just outside of their view. A contrasting approach may be to create a very sparse ambience to help reinforce the feeling of being alone. It is often a creative choice when deciding which of these approaches to use. Often, both approaches will be used interchangeably within the same game at different points to reinforce the story or to provide variety.

Another stylised use of sound can be the creative use of reduced or increased frequency range across the entire mix. This can be particularly effective if you are trying to communicate a feeling of disorientation, as used in the famous beach landing scene in the film Saving Private Ryan (1998).

The tagline from the classic Ridley Scott movie Alien (1979) states correctly that ‘In space, no one can hear you scream’, due to sound waves being physically incapable of traveling through outer space. However, almost every movie set in space will feature atmospheric sound. Not including these sounds would result in what would potentially be a dull and almost silent film experience. Can you imagine what it would be like in the Star Wars series if all the space battle scenes involving X-Wings, Tie Fighters, and Death Stars were completely silent?

Sometimes using no sound, or creatively ‘breaking the rules’ by exercising creative license to add in additional sounds, can be more effective than providing literal sound design. To effectively break from convention, you will need to have a clear understanding of why these so-called ‘rules’ have become established protocol and the effect breaking these will have on the player/viewer.

5 quick tips

As with film, don’t always trust your ears listening to sounds in isolation; you must learn to trust your eyes when playing the game. It’s more important that a sound looks right in-game even if it sounds out of place, weak, or uninteresting in isolation.

It is the contrast between quieter, smaller, simpler sounds that allow the louder, bigger, and more detailed sounds to have impact and really define the mix. Without contrast, the entire game could sound flat, lifeless, and lacking in definition.

If you find that a sound you have created does not quite fit when playing inside the game, sometimes it’s quicker and more beneficial to start over from scratch rather than spend a large amount of time trying to ‘force it to fit’.

You can always capture a small segment of video for the gameplay sounds you are designing. This will allow you to hear how the sound you are creating will fit into the final mix with all the other audio. This is something I did frequently at the start of my career. You will find that with time and experience, you are able to listen to the game, establish what frequency ranges etc. are needed in the sound, and make it in isolation, confident it will fit into your existing mix without needing to hear the accompanying Game Audio.

With sound design, experimentation is key; everything is worth trying out at least once. You never know when a happy accident will occur or when that weird recording using a malfunctioning microphone you made a long time ago may come in handy. Creative use of layering and sonic processing can transform everyday sounds into something spectacular.

Chapter 2 practical task

The practical task for Chapter 2 is to revisit a few of your favourite games, and, armed with this new knowledge, try listening to the sound when playing in a more analytical way rather than just experiencing the game as a consumer.

In particular look at the following areas:

What kind of atmosphere is the game trying to create, e.g. horror or playful, realistic or fantasy?

What sounds can you hear that are diegetic?

What sounds can you hear that are non-diegetic?

What type of sounds are the most important in this particular game?
 (Does this correspond to the frequency ranges and volume balance allocated to these sounds?)
 (Does this change between similar games within the same genre? If so, how?)

How are the frequencies within the mix spread out amongst the various sounds?
 (Does this change throughout various points in the game if you play in a different way?)

Can you hear any instances of interactive processing within the sounds?
 (If so, how is the sound processing changing based upon your actions?)

Learning to critically analyse professional game releases is key to beginning to recognise established sound design practices. In effect, you are learning to reverse-engineer any cool or interesting ideas that you can directly take inspiration from, or repurpose in an original way, when working on your own games.

3 Game sound editing techniques

DOI: 10.4324/9781003055167-3

In Chapter 2, you learned about game sound design in more of a theoretical way, outlining a number of approaches you can take in your own sound design. In this chapter, you will focus on practical sound design techniques used to edit and create sounds suitable for use in a game engine.

The information and practical tasks you will learn and complete in this chapter directly leads to Chapter 4, where you will then take the game-ready SFX you have made and begin to actually play these sounds inside Unity in a first-person playable game level.

When making sound for games you have to consider two main factors.

The Audio Assets that you have made for the game and how those sounds interplay with the game engine to create the experience that will best immerse the player. Knowing the systems available to you and how you can manipulate them to produce playback of your Audio Assets is crucial in determining the immersive capability of your game.

In my experience it is often the main challenge of a Game Audio Designer that what you make outside of the game engine in your DAW and what the game actually plays/sounds like can be very different!

The relationship between the game engine mechanics and the links to the audio being instructed by the game to play is complex and interactive. So you have to consider when making your sounds how, when and where this particular sound will be played for this specific event to ensure each part is playing appropriately. For example; you do not want the reload of a gun to play on loop while reloading, or to have only one sound to be played repeatedly every time you reload the gun or to have it play on longer than the event requires.

There are many scenarios that you will come across as a Game Audio Designer that will force you to reconsider how the sound has been implemented and therefore how the audio files you create will sound in the game!

The overall audio experience will always be constructed in how, when and where the sound is triggered. Breaking down the sequence of each part that contributes to the production of your audio will give you the keys to making your sounds respond to the game and enhance the immersion.

Thomas J. Wolland
(Sound Designer, Supermassive Games, Yoozoo Games, TT Fusion)

Editing techniques

Variety is the spice of life

When creating Audio Assets for games, one additional main difference compared with traditional post-production is that Sound Designers would quite often create a number of variations of a sound as a video game can be played for potentially hundreds of hours. In Audio post-production for film and TV, Sound Designers would generally create sounds one at a time to correspond exactly with the action that is happening on screen.

In video games, the main reason you will create multiple variations of a sound is to help alleviate the repetitive nature of repeating sounds. Imagine if you were playing a game how quickly it would become annoying and distracting if there was only one footstep sound playing continuously for hours on end.

When creating a number of variations, it is important, when choosing a set of sounds, to pick and process samples so that they do not sound drastically different. It is important to remember that all the sounds should sound like variations of a single sound source rather than just a random selection of sounds with similar processing applied.

If you imagine, when creating a set of footsteps variations, you select one recording from a person wearing a pair of high heel shoes walking on a wooden floor, and the next recording is from a pair of work boots walking on tiles. If you attempt to use both of these recordings interchangeably as variations for the same character footsteps, this will not sound natural when switching between the two sounds. This will be distracting or confusing for the end user as the individual sounds are too different from one another.

To create additional variations for a sound, there is a quick and effective technique you can use if the sounds you have created consist of multiple layers. For example, if the sounds consisted of three layers, you could mix and match the layers within the sounds to create additional variations.

In Figure 3.1.1, you can see three sound variations, consisting of three different layers.

Figure 3.1.1 Variation Sound Design Layers Original Arrangement

Figure 3.1.2 shows how the sound layers have been combined in different orders and shuffled to create an additional three variations, bringing the total number of variations to six.

Figure 3.1.2 Variation Sound Design Layers Alternate Arrangement

If you need to create additional variations of a sound, using a limited amount of source material that may not contain multiple layers of audio, the following technique can be very effective. It is possible to edit two recordings from the same sound source and turn this into four variations of a sound. To achieve this, you split the individual sound samples into the transient (beginning) and the tail (end) portions of the sound. You would then duplicate the samples so that the transient and the tail are swapped; this can often sound different enough that the sounds are not perceived as identical.

Figure 3.1.3 shows how you can turn two sound samples into four variations.

Figure 3.1.3 Variation Sound Design Single Layer

Having more sound sources will then enable you to combine the sounds in different ways, potentially turning 4 sound sources into 16 and 6 sound sources into 36 different variations by combining the transient and tail portions of the individual sounds.

As a general rule, the more often a sound will be played, the more variations you will need to prevent the sound from becoming repetitive. For example, in a platforming game where the footsteps will play very frequently and be heard probably thousands of times throughout the game, you need to create between 12 and 20 sounds for each individual surface the player may stand upon, such as grass, stone, metal etc. For a sound that repeats less often, such as a player respawn sound that may play infrequently, say 50–100 times during the same typical platforming game, between four and eight sounds will probably be enough to stop the sound from becoming predictable and annoying to the player. For a sound such as a logo sound that will play once every time the player starts the game, one sound variation is appropriate.

As with many things in life, you should use your own best judgement. When working on a game, you will probably spend more time in total playtesting your own work than an average player will completing the game. If you find a sound is becoming repetitive while working, chances are a player will also. If this happens, consider increasing the amount of variation to combat this.

Mono sounds

When exporting sound, the general rule is that they should be mono if the intention is to play the sound from a specific point in the world, also known as diegetic. Examples of this type of sound are sounds from a character, a gun, or if the sound is placed as if emanating from an alarm in the level. The reason you would do this is because if the sound is mono, it will allow Unity to pan the sound around the soundfield and apply any volume changes, depending on how close or far away the GameObject is.

If you do attempt to play a stereo sound back positionally, Unity will sum the stereo file, effectively turning the Audio Asset into a mono audio file. However, this wastes valuable storage space and is not very efficient. Stereo audio files take up twice the file storage as mono files, and Unity is forced to allocate some of the processing budget converting sound files in ‘real time’ which could be better used in other areas.

Stereo sounds

If the intention is to have a non-diegetic sound that does not originate from any particular point in the gameworld, you will export these as stereo. Examples may include background music or ambient sounds, such as the distant rattles from various machinery or the hum when inside a spaceship. Usually for stereo sounds, you do not want this audio to change volume or panning when the player moves around the level.

Loop editing technique

You should aim to make an ambience or music loop no shorter than 60 seconds, and ideally between 90 seconds and 4 minutes, so that if you include some modulation within the sound, it will not quickly become repetitive and predictable for the player. If the loop is for an element of gameplay, then it can sometimes be shorter; you can use your own judgement for this. Again, if you find the loop sounds repetitive when playtesting the game yourself, then chances are a typical player will also. If this is the case, try revisiting the sound and re-editing it to increase the length of the audio file.

Another technique to reduce repetition in Game Audio loops is to create the ambience layers as separate audio files such as wind, room tone, or background sounds. Not only will this allow you to use the various ambience elements across individual sections of the game, it also increases the sounds flexibility. If the loops are different lengths, then they will overlap with each other at different points in time. This will create an ambience that is more dynamic, immersive, and less likely to become repetitive within a short space of time, than if all the ambience sounds were created and mixed together in a single audio file.

Figure 3.1.4 Ambience Layering Using Audio Files with Differing Lengths

A common issue when trying to create seamless loops is ensuring that the start and end of the sound file are indistinguishable. Sound Designers often want the sound to have complex or changing timbres and transients, to give the sound more character so it does not become boring to the player. One issue is that trying to create a loop using complex source material can be quite difficult, fiddly, and time consuming as it is very obvious where the looping point for the start and end of the sound is.

One technique that will work in over 99% of cases to edit a looping sound, ensuring it will sound seamless from the end, back to the beginning, is called the Top and Tail Technique. This involves splitting the sound at a zero cross point approximately 25% from the start of the file, ensuring you do not add any fade ins or out. You would then take the first 25% edited file and place it at the end of the original file, creating an equal power crossfade where the files meet. This will allow you to mask where the actual edit for the file is, while maintaining the same average volume when transitioning between the two parts of the audio file. When listening through, when the file reaches the loop point at the end and returns back to the start, it will sound natural. This is because in effect the start and end points are how the file originally would have played and the crossfade is obscured. After rendering the sound, you may hear a slight click or pop as it loops from beginning to end. You can fix this by adding a tiny fade in and out over a few samples or milliseconds. The idea is that you shouldn’t be able to hear the fade but that it will smooth out the offending click or pop.

Tip

This may take some experimentation deciding how to create the crossfade to blend most naturally.

Using an equal gain fade ‘X’ may result in a drop in volume. Using a Logarithmic Equal Power fade should ensure a smoother transition.

Figure 3.1.5 Creating a Seamless Loop

Export settings

I recommend exporting/rendering all audio in a 48 kHz, 16-bit. wav file format, as you can then choose to apply data file compression inside Unity and tailor this to create various file formats for specific platforms such as .wav for PC games, .ogg for mobile games etc.

It is very important when creating loops that you do not export these as. MP3 or other lossy file formats.

The MP3 file format will include a small amount of silence at the beginning and end of the file for the metadata. If you attempt to loop an MP3 piece of music or ambience, you will find that it will not loop seamlessly due to this small amount of silence.

I would advise exporting all your sounds as .wav to ensure the audio does not suffer from data compression artefacts that may cause issues such as this.

At the time of writing, I personally don’t see a major benefit in exporting sounds in 24-bit or at higher sample rates, as the trade-off between the file size and any additional benefits to the audio quality is currently not worth the additional increase in file size. However, this may change with future consoles and increased PC storage capacity. At present I would recommend using the space saved by exporting at 48 kHz, 16-bit to add in additional variations and longer loops. At some point in the future when data storage is no longer a major concern, then using 24-bit, 192 kHz sound files will inevitably become the standard.

It is generally considered best practice to export Audio Assets in a high-quality format from the DAW and then apply data compression or file conversion inside the game engine. This allows you to create a backup of high-quality Assets should they ever be required in the future when porting the game to another platform or creating a remaster.

What is a Wave Editor and why might you use one?

When you have created your Audio Assets and exported them from your DAW, it is typical in a Game Audio workflow to then import them into a Wave Editor such as Adobe Audition, Soundforge, or the free options Audacity or Ocen Audio to perform the final edit and volume processing. There is typically nothing a Wave Editor does that a DAW cannot also do. Game Audio professionals tend to use Wave Editors to perform the following processes as it is quicker and easier to import, export and perform simple edits compared to a full featured DAW. You will use these to trim any unnecessary silence from the beginning and end of all Audio Assets. There are several reasons to do this. This book will demonstrate how to use Audacity to perform these tasks; however, the techniques are directly applicable to any Wave Editor you choose to use.

Seamless loops

Seamless loops mean there will be no gaps at the start or end of the audio. You can also edit the start and end to have a seamless Zero Crossing Point to make sure that no artefacts such as clicks or pops are present.

Instantaneous playback

When you set up the game to play audio at a certain event or time, you would expect this to happen instantaneously. If you have sections of silence at the beginning of Audio Assets, this will mean that you will hear the sound later than it has been triggered. Leaving unnecessary silence at the start of an audio file can be off-putting for games that require instantaneous aural feedback from player actions such as FPS. If you press the shoot button, the expectation is to hear the gunshot as soon as the button has been pressed; if the audio file features silence at the beginning, the player will experience this as the audio being delayed.

If variations of a sound have different amounts of silence at the start of each individual audio file, then the sound will appear to trigger, not only later than expected, but also randomly, and there will be no way to control this. This will be particularly off putting for the player, as not only will it be distracting but they will feel as though their actions and the audio have no correlation.

Editing audio in Audacity

After you have created and exported your Audio Assets in a DAW, you will import them for editing and processing into a Wave Editor such as Audacity. After installing and opening up Audacity, it will initially look like the picture in Figure 3.2.1.

Figure 3.2.1 Audacity Main Window

To edit and trim the silence from the beginning/end of files and add to any fade ins/outs, you will primarily be focused on the main Audacity Project Window.

To import audio into Audacity, you select the audio files wherever they have been saved on the computer and drag and drop them into the blue section of the Project Window.

Audacity project window

The Project Window will now show a visual representation of the waveform in the file.

Figure 3.2.2 Audacity Project Window

How to edit audio in Audacity

Although at first glance Audacity may look very complex, editing audio inside Audacity is actually fairly intuitive if you have previous experience with any DAW. One feature is the ability to quickly save custom shortcuts for any process. The following are a few of the commonly used default shortcuts.

Start and stop playback using Spacebar key

Delete selected audio using Backspace or Delete key

To select the entire waveform, Double Click

To zoom in/out Waveform, hold down Cmd button on OSX and Ctrl button on Windows while moving the Scroll Wheel on mouse

Move section to start of file: Function + Left Arrow on OSX or Home on Windows

Move selection to end of file: Function + Right Arrow on OSX or End on Windows

Select Zero Crossing Point: Z key

Export current file: Cmd + Shift + E on OSX or Ctrl + Shift + E on Windows

Close current file: Cmd + W on OSX or Ctrl + W on Windows

To highlight a portion of sound to edit, place your mouse cursor at the desired point in the Editor window, hold the left click button, and drag the mouse to the left or right to highlight a section of the audio file. Currently selected audio will appear highlighted in a lighter shade of blue.

Figure 3.2.3 Audacity Selecting Silence

You can then choose to delete the highlighted audio by pressing the delete key on the keyboard. Remove the silence at the beginning and end of the sound so that the Waveform looks like the image in Figure 3.2.4.

Figure 3.2.4 Audacity Audio File after Silence Trimmed from Start and End

Audacity (and most other Wave Editors) also have a feature to enable editing on Zero Crossing Points when using the selector tool. A Zero Crossing Point is where the amplitude of the sound file is at zero and can be seen when the Waveform crosses between positive and negative (the black line running through the waveform). This is very useful, as trimming audio on a Zero Crossing Point will reduce the chances of causing a click or pop when listening back to the file. For many editing tasks, such as deleting, splitting or inserting audio, Zero Crossings are the best places to edit the audio. Selections that begin and end at Zero Crossings reduce the chance that edits will create undesirable artefacts such as audible pops or clicks. To adjust a selection to the closest Zero Crossing Point, click on the Select menu and choose At Zero Crossings, or alternatively press the Z key to make the selection cursor jump to the nearest Zero Crossing Point.

When editing loops, always listen to the audio file playing through the start/end of the loop point inside Audacity. In my experience, I have found that when creating loops inside DAWs, after exporting there can sometimes be an audible click or a pop at this start/end point. This can be fixed easily in Audacity by zooming into the start and adding a fade in over a few samples, then zooming into the end of the file and adding a small fade out over a few samples.

Figure 3.2.5 Audacity Fade In

Normalization

Peak Normalization is the process in which Audacity will scan each audio file for the loudest peak in the waveform and then raise the overall level of the audio file to a preset volume. This is very useful as it gives you a standardised volume between all of your audio files. This means that all the variations of a sound will now be roughly the same volume and, equally important, that these variations of audio files will be roughly the same volume as every other audio file in the game.

Ensuring that all files have been correctly edited and normalised will make mixing the audio in the game substantially easier.

You will follow standard professional practice and peak normalise all audio files to −1 dBFS peak. This means that the loudest part of the sound will be increased to −1 dBFS. It is important to ensure all audio files are rendered out of your DAW at a reasonable volume and normalised to −1 dBFS. The Unity audio engine is not able to apply positive gain to increase the volume of Audio Assets through the Audio Component used for adjusting the volume of individual sounds. Audio files are typically imported at maximum volume and then turned down or attenuated inside the game engine when mixing.

To bring up the Normalize Window you will select it under the Effect menu found in the top of the screen and then select Normalize.

Figure 3.2.6 Audacity Normalization

The Normalize Window will now appear as a pop up. This will allow you to set the parameters to Remove DC offset, to Normalize peak amplitude and set the peak normalize dB target level. It also gives an option to Normalize stereo channels independently.

For all sounds, dialogue, and music, use the default settings as shown in Figure 3.2.7 and then press the OK button.

Figure 3.2.7 Audacity Normalization Window

Tip

As Normalization is a tool that you will use often, you may want to assign a keyboard shortcut to this function to save time.

To save the file, select the File Menu options, then Export, and finally Export Audio.

Alternatively, use the keyboard shortcut Cmd + Shift + E on OSX or Ctrl + Shift + E on Windows.

Figure 3.2.8 Audacity Normalization Window

Navigate to the folder with the original audio file that was dragged and dropped into Audacity and double click on it to overwrite the original with the edited and normalised version created using Audacity. A popup box will then appear, warning that you are about to overwrite the original file.

Select Yes.

A further dialogue box will popup asking if you would like to edit any Metadata Tags.

Metadata can be used to embed additional information alongside the audio file such as track and artist name. The metadata options offered in this popup menu are not particularly relevant to Game Audio Assets for use inside Unity, so you should select the ‘Don’t show this when exporting audio’ checkbox so you don’t have to view this screen and speed up the export process.

Finally, close the Audacity project; generally, you would not need to save this as you have just exported the sound. Should you find at a later date you need to re-edit, it should be quick and simple to re-import the file into a new Audacity project.

Close the current Audacity project by selecting the File Menu and selecting Close or using the keyboard shortcut Cmd + W on OSX or Ctrl + W on Windows.

5 quick tips

It’s important to always save and keep a backup of all of your DAW projects for your audio in case you ever need to revisit a sound during development, or in the future if the game will be remastered for a future console.

Using the Batch Processing function to apply similar processing such as Normalization using Wave Editors can save you a lot of time, especially when processing, editing, and exporting multiple variations of audio files simultaneously.

Customising shortcuts and saving presets can save you a considerable amount time when editing and exporting Audio Assets.

You can often spot any potential issues, such as clipping, or that you have accidentally exported a mono sound as stereo, quite easily within a Wave Editor.

There are a number of alternate Wave Editors available with varying additional features; it may be worth also exploring these other options to compare features.

Chapter 3 practical task

Download and view the silent Chapter 3 Practical Viking Village Video .mp4 video file. This will enable you to have a look at the playable level that will be used for the Chapter 4 practical task. After viewing the video file, the practical task for this chapter is to assess and then make the looping sounds that are required for this game level. Please keep these sounds at hand on your computer as you will then implement these in the level for the Chapter 4 practical task.

Look through the silent video file to see the game. Think about what kind of atmosphere/ambience you would like to develop using audio.

What sounds would you expect to hear from the ambience, wind, birds etc?

How sparse or populated is the level?

Could you hear anything you can’t directly see?

(Examples could include wildlife or sounds coming from within the various wooden huts.)

Have a look for any reference material from similar films/TV/games for additional ideas.

Figure 3.4.1 Screenshot Taken from Unity Viking Village Level

Next, create these individual sounds as 16-bit 48 kHz .wav Seamless Looping Ambient SFX Audio Assets. Check that all of your audio files are correctly Normalized to −1 dB, that there is no silence at the beginning or end, and that there are no unwanted artefacts like pops or clicks at the beginning or end of the file. Use whichever DAW and Wave Editor you feel most comfortable with.

If you do not yet have a favourite, I highly recommend REAPER, as it is highly regarded within the Game Audio community for its flexibility. I have personally used REAPER for the last few years as my main DAW; it also has a really useful Media Explorer function included that will enable you to quickly search through all of your audio samples when searching for specific sounds such as birds, water, or wind.

You can try out a fully functional 60-day trial for free: www.reaper.fm/.

While it is always great to record your own library of recorded sound sources, sometimes it just isn’t practical to record explosions or car crashes. You will also find a PDF featuring links to various free resources included in the Chapter 3 DLC folder for this book. This PDF includes links to websites where you can download 500+ GBs of sound recordings, featuring many different sound resources that you may find useful for this chapter and the main game project.

Finally, ensure you keep all of the sounds you have created safely stored inside your computer as you will be implementing these directly inside this Viking Village game level in the practical task for Chapter 4.

4 Importing assets into Unity and placing sounds in gameworld

DOI: 10.4324/9781003055167-4

So far, this book has covered various issues dealing with the planning and the creation of game-ready sound files. The previous chapters focused upon sound design and creating the sound files.

This chapter will focus primarily on best practices for importing and implementing your own audio files inside Unity. Implementing is a term that covers actually getting the SFX, ambience, dialogue, and music audio files you have added to Unity to actually play in the game.

Finding the right ambience is crucial for maintaining immersion. A tasteful combination of diegetic and non-diegetic environmental audio can help suspend the player’s disbelief, further transporting them into the game world. In addition, having an ‘underlayment’ of a sparse, looping stereo ambience coupled with positional, randomly timed one-shot sounds reduces predictability, and decreases the chance of listener fatigue. If their ears can’t latch onto repeating patterns in the ambience, the immersion is retained, allowing them to focus on the more immediate auditory events in gameplay.

When I first worked on the city builder Children of the Nile (2004), developed by Tilted Mill/SEGA, I found that the fixed, 2D stereo outdoor ambiences weren’t sitting right in the mix. There were different looping sounds for the varied outdoor environments, with everything baked into WAV files. Crossfading between environments was fine, but the ambiences themselves grew old quickly.

In one example, when the camera hovered over grasslands, the player would hear non-diegetic birds chirping with a gentle, diegetic water rushing sound effect (the Nile river flowing on screen). The problem was the non-diegetic elements sounded too repetitive. So, I decoupled the animal sounds, triggered them at random time intervals, and only at certain times of day. So at night, those bird calls were replaced by non-diegetic jackals! Each animal call had multiple variations, and limits were placed on the number of calls heard at any one time.

This control level may seem excessive, but it was the system that resonated with everyone. Often, it’s this level of complexity that’s needed to make the interplay of diegetic and non-diegetic ambience fun to listen to. Bear in mind, though, it wasn’t a ‘eureka’ moment that brought about this design – these systems take time to flesh out, and lots of iteration goes into building it as well as in crafting a smooth, compelling mix.

When your ambience implementation finally ‘clicks’ into place, you will know it, and it’s an incredibly exciting feeling! It feels even better when your team – and ultimately the players – get to experience what you have created and can share in that same level of excitement!

Keith Zizza
(Composer, Sound Designer and Professor at Worcester Polytechnic Institute), www.keithzizza.net

How to open the Chapter 4 Viking Village Project

You will be required to download and unzip/uncompress the Chapter 4 Viking Village Unity Project from the provided downloadable resources to follow along with the examples in this chapter.

Unzip/uncompress the folder and open the Unity HUB program. Once uncompressed, using the Unity HUB left click on the Add button.

Figure 4.1.1 Unity HUB Add Viking Village Silent Project

Navigate to the Chapter 4 Viking Village Project folder.

Please note that there may be a folder of the same name located inside the Chapter 4 Viking Village Project folder you just uncompressed.

You need to select the Chapter 4 Viking Village folder located on the level above the individual project folders.

Figure 4.1.2 was taken on a Windows PC and shows the contents of the individual project folders for reference.

Figure 4.1.2 Viking Village Project Folder (Image Taken Using Windows PC)

Trying to open the folder on the incorrect level will result in an error appearing at the bottom of the Unity HUB and the project will not open.

When the Chapter 4 Viking Village Project has been added to the list of Projects in the Unity HUB, left click on the name of the project to open it.

You will find that Unity will perform a simulated import procedure; this could take up to several minutes depending upon the capabilities of your computer, so please be patient. After the project has been opened for the first time on your current computer, it should then open considerably more quickly when re-opening.

If you are opening the project on an Apple Mac computer running OSX, you will likely see a message appear about an Unsupported Build Target.

Figure 4.1.3 Unsupported Build Target Message

If this message appears you should click SwitchTarget. Clicking on Exit Unity or the ‘X’ in the top right corner of the window may still open the project, but you may find that it does not work correctly after opening. If this should occur, the easiest way to solve the problem is to remove the project from the Unity HUB. Re-add it to the Unity HUB and re-open it. This should make the same message appear again, in which case click SwitchTarget.

Once you have successfully opened the project, this SwitchTarget message will not appear again unless you move the project to a computer with a different operating system.

If you do not see this message when opening any of the downloaded projects, this is no cause for concern; please skip to the next section of the book.

Playing the project

The first thing you are going to want to do after opening the Chapter 4 Viking Village project is to double left click on the Viking Village Silent Scene file in the Project Panel to view the game level. Next, you will want to begin walking around, exploring and planning how best to bring life to the world using audio.

First, though, you need to learn about Play Mode in Unity, as so far in this book you have mainly been using Unity in Edit Mode. You have probably noticed the three buttons positioned at the top, middle section of the Toolbar directly under the main menu.

These controls will look familiar to you if you have ever used any kind of DAW. However, they function slightly differently here in Unity.

Figure 4.1.4 Unity Transport Buttons

The icon on the far left is the Play button. This puts Unity into Play Mode and begins playing the game from the currently opened scene. To stop the game playing, you can press the Esc key to bring the mouse cursor back into view. Left click on this button again to exit Play Mode and re-enter Edit Mode.

The middle icon is the Pause button. This will pause the game when it is currently playing.

You will need to press the Pause button again to allow the game to proceed.

The icon on the far right is the Step button. This button will instantly pause the game and allow you to ‘step’ through the game one frame at a time. It is less useful for audio needs but is immensely helpful for Programmers, Game Designers, and Visual Artists.

Importing audio assets into Unity

To import an Asset into Unity, you can accomplish this in several ways. First, you can use the Assets Menu found along the top menu then select Import New Asset and finally locate and select the Asset on your computer.

Figure 4.2.1 Importing Assets Menu

A quicker alternative method is to drag and drop audio files directly into the Assets folder from your Apple Finder or Windows Explorer window; they will appear in the Project Panel.

Dragging and dropping the audio files using this method will cause Unity to copy the files from your folder in your computer, leaving the original files unmodified and in their original location.

Figure 4.2.2 Unity Project Panel

The Project Panel directly corresponds with the folder structure of the Unity Project that can be viewed in the Apple Finder Window or Windows Explorer window.

Figure 4.2.3 Unity Project Panel and Computer Folder Structure (Image Taken Using Windows PC)

You will see, when viewing the corresponding Assets folder, that Unity will not directly convert the audio files. They will remain as the same file format extension as the original file, for example .wav.

Going meta

You may also notice that there seems to be a duplicate file with the same name with the extension .meta. Unity will automatically create these additional metafiles when importing any kind of Asset, such as audio, animation, or art. Unity will also create these metafiles for folders and other elements created within the Unity game engine.

Unity will analyse and process any files that you add to the Assets folder. Essentially, it will convert the contents of the Asset file to internal game-ready versions of the data. The actual Asset files remain unmodified, and the processed and converted versions of the data are stored in the project’s Library folder found in the main project folder.

Unity creates these files for each Asset, but they are hidden by default, so you may not see them in your Explorer/Finder window. You can make them visible by ensuring that hidden files are shown. As each computer operating system is different, and the option to view these can change even between different versions of the same operating system, I would advise googling the name of your operating system plus ‘show hidden files’.

For example, Google Search: ‘Windows 10 show hidden files’.

Warning

This is a relatively simple change, but you should always be careful when changing how your computer operates. I would always advise attempting to find instructions from a reputable source, such as the creator of your software, rather than blindly following instructions you find on an online forum or tutorial video.

I would also advise that you make the metafiles visible in your operating system, but not in the Unity Project Panel as you do not need to directly modify the metafiles in Unity. Changes you make to the file in Unity will be automatically set and stored by Unity in the metafiles. This option should be disabled by default, but if you want to view or hide these metafiles in Unity you can go to the main Unity menu and disable the option using the following menu path:

Unity: Edit Menu > Project Settings > Editor > Versions Control, Mode: Visible Metafiles.

The metafile corresponds with the actual audio file or folder; it contains additional information such as a unique identifier or ID number used by Unity. This identifier links the metafile to the actual Asset file.

One of the most important functions that this provides is that it allows you to rename or move the location of the actual Asset within the Project Panel at any point during development, meaning the .metafile will be automatically renamed or moved also. If you rename or move an Asset into a different folder using the Windows Explorer/Apple Finder window, then the associated. metafile will also need to be manually renamed or moved alongside the Asset file.

This is why I would advise you to add, rename, delete, or move Assets between folders within Unity using the Project Panel as the metafile will be updated automatically by Unity.

The added benefit for you as a developer is that the metafile will remain linked to any corresponding locations it has been used within Unity.

This small benefit is much more important than it initially appears. When actively developing a game, changes can happen at any point and are especially likely as the project grows in complexity. I have worked with other game engines on professionally released games that did not have this feature. This particular game engine demanded a very high degree of accuracy and manual oversight, as a small typo introducing a name change or accidentally moving an audio file to a different subfolder caused major problems anywhere this file was directly referenced and could potentially cause the entire game to stop working and crash.

When I was working on a well-known game using this game engine, in one particular case, a line of dialogue was required to play to completion before awarding a collectable. As another member of the development team had modified the name of the associated character in-game, this meant that the dialogue line could no longer play as the dialogue line was referencing the name of a character that no longer existed. The end result of all of this was that the player was not awarded the collectible when completing the objective.

The knock-on effects of this small fairly trivial change meant that the game could never be 100% completed and that because of this, Sony, Nintendo, and Microsoft would not have allowed the game to be released on their consoles.

In this case, it was lucky the issue was spotted and fixed quite quickly, but if this particular engine had auto updating dependencies using a metadata based system such as Unity, then this issue would have been handled automatically and this would not have been a problem that needed manual correction in the first place.

If you delete any Asset files in Unity using the Project Panel, Unity will automatically also delete the associated metafile. If you delete the same file using the Windows Explorer/Apple Finder method, remember to also delete the associated metafile to avoid causing any errors in Unity. If you accidentally delete just the .metafile, don’t panic. Unity will automatically generate a replacement using the default import settings. For audio, these correspond to the various parameters discussed later in this chapter.

Warning

To ensure Unity is able to automatically perform features such as these, you should not modify this ID number (or any other information) in the metafile using the Unity Inspector or a text editing program.

File naming structures and conventions

It is very important to follow a file naming convention and structure when creating and importing Assets into Unity.

Although this sounds very boring, it is critically important. When dealing with potentially thousands of individual audio files in a large-scale professional game, without a structured and clear file name convention it is very easy to lose track of what Audio Assets are actually in the project or where these are.

Consistency is key. It is less important which file naming structure and convention is used and more that it is strictly adhered to throughout the project. When naming your recorded sounds, you should try to think of as many descriptive sounds as possible; these should be listed in order of importance.

When naming GameObjects in Unity, it is good working practice to give every file and GameObject a unique name. This makes it very easy to search the entire Unity Project when looking for one particular file. This is most easily accomplished using underscores ‘_’ instead of spaces in file and GameObject names. When creating multiple variations of one sound, it is also good practice to number the Audio Assets. I have found that using a numbering system 01, 02, 03 etc. will enable all the variations for an Audio Asset to appear in numerical order when viewing or searching for them inside Unity.

For example: AMB_Wind_Light_01 uses the prefix AMB for ambience and Wind Light as the description and purpose for the sound.

If I had made a number of footsteps, I would use the following as an example of names:

CHAR_CharacterName_FS_Boots_Run_Metal_01.wav

CHAR_CharacterName_FS_Boots_Run_Metal_02.wav

CHAR_CharacterName_FS_Boots_Run_Metal_03.wav

CHAR_CharacterName_FS_Boots_Walk_Grass_01.wav

CHAR_CharacterName_FS_Boots_Walk_Grass_02.wav

CHAR_CharacterName_FS_Boots_Walk_Grass_03.wav

A few examples of name prefixes that I would use are as follows:

AMB: Ambient SFX

CHAR: Character SFX

COLLECT: Collectable SFX

CUT: Cutscene SFX

DEST: Destructible SFX

DX: Dialogue

ENEMY: Enemy SFX

MUS: Music

UI: User Interface SFX

VEH: Vehicle SFX

As you create more of your own recordings, or the game you are currently working on becomes more complex, well-named files and a consistent structure will allow you to easily find and organise all of your audio files.

Every Game Audio professional will have their own unique workflow; this includes not only the DAW and plugins they use but also how these projects/sessions are organised. Some people will make all the sounds for the entire game, a single character, or a weapon inside of a single DAW session, and others will use a separate session for each sound.

No one person’s workflow is inherently better than another’s; it is something personal and unique that you tend to continually develop and tweak over time. My own preference is to create a single REAPER DAW project for each sound I make. I then structure my Unity folders and Audio Asset names to directly mirror that of my DAW projects. This allows me to easily find anything that I may need to tweak later in the game’s development, for example a visual effect on a weapon is modified or an animation length is changed and the sound needs to also update to reflect this.

Unity allows you to create as many subfolders for Assets as you require, which enables you to keep all the sound, animation, and art files organised. It is common when importing Audio Assets into Unity to place them inside folders corresponding to the prefix name of the audio file.

Figure 4.2.4 Folder Example Names in Project Panel

If a folder will contain many Assets such as vehicle sounds, it may make sense to create additional folders inside the VEH folder for the various vehicles in the game. It should be noted that the main purpose of the folder structure is to enable easy organisation and allow you to quickly find the Asset you require.

Every individual sound does not need to be grouped into its own separate folder which is nested ten sub-folders deep in the Audio Assets. How organised and subdivided your Assets folder is a matter of the project requirements and personal taste.

Viewing imported audio files in Inspector

If you select an imported sound, you can see a variety of adjustable parameters in the Inspector Panel. You can select multiple audio files at once to change similar parameters as a group, rather than adjusting each Audio Asset individually.

Figure 4.2.5 Audio Asset Inspector Parameters

Force to Mono – Enabling this option will downmix and combine a stereo signal making it mono.

Normalize – This option will only work with Force to Mono. It attenuates the waveform −3 dB to gain match the Audio Asset when combining stereo signals into mono. (Not the same as Normalization as covered in Chapter 2.)

Load in Background – This option will load the audio file while the game is running in the background.

Ambisonic – Should be used with B Format Ambisonic .wav files for VR/ Binaural applications. (Leave disabled as this book will not specifically cover VR/AR.)

Load Type – How Unity will load the audio file. (Various load methods discussed in later chapter.)

Preload Audio Data – This will stall the game until the audio has loaded into R.A.M.

Compression Format – This will let you choose which file format to use when compressing full quality. wavs.

Quality – How much data compression is applied to the audio file. Lower quality means smaller audio files but reduced quality.

Sample Rate Settings – This will let you choose which sample rate to play the audio file as.

Revert Button – This will revert or disregard any changes made.

Apply Button – This will apply any changes to the Audio Asset.

Name – This is the name of the Audio Asset.

AutoPlay Button – This will automatically play the Audio Asset currently selected.

Loop Button – This will allow you to loop the sample in preview mode.

Play Button – This will let you play and preview the sample.

You DO NOT need to modify any of these settings when importing audio assets at this time. These parameters will be revisited and explained in greater detail during Chapter 13.

Updating/replacing existing Audio Assets

It is common after creating an Audio Asset and hearing it in the game, that you decide it is not quite right and will need to be modified or updated. This could be because it does not cut through the rest of the sounds, is repetitive, or perhaps does not loop correctly.

If you try to replace the files using this drag and drop method in Unity, it will realise that these files already exist and rename the newly imported files, keeping the original files as well. This can quickly result in your project becoming bloated and containing many files that are not required. This increases your project size unnecessarily and makes it harder to know which version of a file you intend to use in the final game.

If you want to replace existing Audio Assets, the easiest way to do this is to give the replacement Audio Assets an identical name. Right click on the Audio Asset in the Unity Project Panel and select Show in Apple Finder/Windows Explorer to open up the folder on your computer with the audio files. Then drag the new replacement audio files over the existing files to replace them. Unity will then update the Assets inside the game engine automatically. When using this method of adding/replacing audio files in Unity, you can either directly move the audio files from a folder in your computer or copy and replace these, depending upon which method you choose to use on your operating system. In essence, this will function much like copying and replacing any existing type of file between two folders in your computer.

It is important to note when replacing any Assets in Unity using this method that this change is permanent and cannot be undone.

It is important to ensure you do not accidentally replace the updated file in Windows Explorer/Apple Finder with the original Unity file.

Figure 4.2.6 Unity Show Asset in Explorer/Finder (Image Taken Using Windows PC)

Introduction to AudioSource and Audio Listener Component

A Game Audio engine works using a similar principle to recording audio. When recording using a DAW, you typically have a sound source or sources creating sounds, such as a guitar amp or drum kit, and a microphone that listens and captures the sound. In a game engine, the AudioSource Component typically provides the sound source, acting like a guitar amp, and the GameObject that picks up the sound like a microphone is called the Audio Listener. For the rest of this book, it may be referred to as simply just the Listener.

Audio Listener Component

The Listener can be thought of as the equivalent of your ears in the game. It receives or ‘listens to’ AudioSources that are in the gameworld. The behaviour of the sound source in the game is controlled by the AudioSource Component.

As in real life, when walking around a room you will hear a change in the volume and panning of a sound source such as a radio or TV. The Unity Listener will pick up and process audio in the same way. You can use the controls on the AudioSource Component to alter how pronounced you would like these panning and volume changes to be.

To hear audio playback in Unity, each Scene must have an Audio Listener Component. The Listener Component will have no adjustable settings or parameters.

The Listener is typically attached to the game camera or player character. There are certain situations where you may want to temporarily move the Listener to a different GameObject, such as during a cutscene. The Listener may move from the player to the camera during the cutscene and then back to the player when the cutscene has finished. This can be achieved using a programming command but it is very important to know that much like you only have one set of ears, Unity will only allow one active Listener in a Scene at any one time.

Unity, by default, will create a Listener Component on the Main Camera. You can see the Listener Component in the Inspector Panel if you select the FirstPersonCharacter GameObject in the Viking Village Project using the following Hierarchy path:

PlayerStartLocation > FPSController > FirstPersonCharacter

Figure 4.3.1 Unity Audio Listener in Viking Village Project

AudioSource Component

If you use the previous analogy and consider the Unity Listener as acting like a microphone, then an AudioSource Component can be thought of as a speaker emitting sound in the gameworld. The main difference between a speaker and an AudioSource is that an AudioSource will radiate sound out equally in all directions, rather than directionally as a typical loudspeaker would.

AudioSources contains a variety of controls that tell the game engine how you want the sound to play when triggered in the game engine.

Figure 4.3.2 AudioSource Parameters

Inspector – All AudioSource Components will automatically create a Component at the top of the Inspector. As with any GameObject, this can be used to rename and turn any GameObject on and off.

Transform – All AudioSource Components will also automatically create a Transform Component to tell the game engine where the AudioSource is placed in the gameworld.

AudioClip – The AudioClip is where you load in the Audio Asset the AudioSource should play. You can either drag and drop imported audio files from the Unity Project Panel into the box or alternatively, click the small circle to the right to search and select it from the Asset folder.

Output – The Output is what channel/group you want the audio to be routed to in the Unity Mixer. (This will be covered in Chapter 12.)

Mute – This toggle switch will allow the AudioClip to play but will mute its Output. (Much like any DAW.)

Bypass Effects – This toggle will allow you to bypass any audio effect Components you have added. (Effects will be covered in Chapter 12.)

Bypass Listener Effects – This toggle will bypass any Doppler pitch effects applied automatically from the Listener.

Bypass Reverb Zones – This toggle will bypass any reverb effects you have applied to a game area. (Reverb will be covered in Chapter 7.)

Play On Awake – If this is enabled, the sound will play as soon as the GameObject is activated.

Loop – If this is enabled it will loop the AudioClip as soon as it reaches the end. (Much like the behaviour in any DAW or Wave Editor.)

Priority – This is how to set how important a sound is. If you begin approaching resource limits, Unity will have to stop playing some AudioClips. You can use this slider to assign priority values to each sound; Unity will then stop playing lower priority sounds in favour of higher priority sounds. In this case, 0 is the most important and 256 is the least important.

Volume – Sets the volume of the AudioClip on a linear scale from 0–1 with 0 being quietest and 1 being loudest.

Pitch – Allows you to pitch sounds using the game engine; this is achieved by changing how fast or slow an Audio Asset will play. It ranges from −3 octaves to +3 octaves.

Stereo Pan – This will allow you to adjust the stereo position of 2D sounds. It functions much in the same way as a traditional pan parameter in a DAW.

Spatial Blend – This will set how much the AudioSource is treated as a 3D source. 3D AudioSources automatically have panning applied.

Reverb Zone Mix – This works like an Auxiliary send in a DAW. If a Reverb Zone has been set up in the level, this will adjust how much signal is sent to it. (Again, this will be covered in Chapter 5.)

It is essential to then link or assign your audio files to an AudioSource so they can be played back within the game. This can be accomplished using either of the two methods outlined next.

The first is to click on the small circular icon directly on the right-hand side of the AudioClip parameter.

Figure 4.3.3 Adding AudioClip to AudioSource (Select Method)

This will bring up a pop-up menu featuring all the audio files within the project. You can search for a specific sound by name using the text box or simply double left click on the AudioClip to assign it to the AudioSource.

The second method is to directly drag and drop the AudioClip straight from the Project Panel into the AudioClip parameter of the AudioSource.

Begin by navigating to the folder within your project with your audio file.

Select the AudioSource in the Hierarchy.

Left click and continue holding down the mouse on the audio file.

Move your mouse over the None (AudioClip) parameter on the AudioSource until it turns blue.

Let go of the left click to drop the audio file in the AudioClip parameter.

The AudioClip parameter should now contain the name of your audio file.

Figure 4.3.4 Adding AudioClip to AudioSource (Drag and Drop Method)

Your AudioClip will now be assigned to the AudioSource.

Figure 4.3.5 AudioSource With Assigned AudioClip

Figure 4.3.6 AudioSource 3D Sound Setting Parameters

3D Sound Source Settings – This dropdown will let you hide or view the 3D Sound Settings parameters.

Doppler Level – This will adjust the amount of Doppler applied for each AudioSource. If set to ‘0’, then no Doppler is applied; if this parameter’s value is increased past ‘1’, the Doppler effect will be exaggerated.

Spread – This will set the angle to 3D or Surround Sound sources. (Part of the sound panning settings and is often called ‘Divergence’ in other DAWs.)

Volume Rolloff – This setting will affect how quickly the sound will ‘fall off’ or get quieter as you move away from the sound source. This works much like conventional Fade settings in a DAW but will work over distance rather than time. It can be changed to Logarithmic, Linear, or Custom.
  Logarithmic – The sound is loud when you are close to the AudioSource, but when you move away from the AudioSource it decreases quickly, replicating most closely how sound behaves in the real world.
 Linear – The sound will get quieter directly in proportion to the distance from the sound source.
 Custom – The sound from the AudioSource behaves according to how you set the nodes on the graph for the Volume parameter.

Min Distance – When the Listener is within the Min Distance, the sound will play at maximum volume. Outside of Min Distance, it will begin to get quieter.

Max Distance – The distance at which the sound fades down to silent.

Graph – This graph will attempt to show each of the previous settings. You can left click to move any of the nodes on the graph and drag them to adjust the corresponding parameter.

Placing AudioSources in gameworld

To create an AudioSource Component, you can either right click in the Hierarchy Panel and select the Audio category and AudioSource, or alternatively select the GameObject menu in the top left then select Audio and AudioSource.

Figure 4.3.7 Creating an AudioSource

The AudioSource will then be created and a graphical GameObject that looks similar to a loudspeaker icon representing the AudioSource will appear in the Scene View Panel if the Gizmos button is activated.

Figure 4.3.8 AudioSource Min and Max Distance Gizmo Visualisations

In Figure 4.3.8, I have set the AudioSource Min Distance parameter to 4 and the Max Distance parameter to 12.

As you can see from the image in Figure 4.3.8, the inner circle represents the Minimum Distance and the outer circle represents the Maximum Distance. These correlate to the Min Distance and Max Distance parameters. Unity by default will set the Min Distance to 1 and the Max Distance Value to 500.

If you cannot see the Min and Max visualisation spheres, check you have the Gizmos button enabled in the Scene Panel and set the Min Distance value to 5 and the Max Distance to 10.

The player will hear the sound at full volume when the Listener is inside the inner circle (Min Distance). As the Listener moves from the edge of the inner circle to the outer circle, the sound will begin to get quieter. When the Listener is outside of the outer circle (Max Distance), the sound will be silent.

Unity by default will NOT make your AudioSource inaudible when outside of the Max Distance. this has been present in Unity for a number of years and in my opinion is a silly default setting.

This default setting means your AudioSource will still be audible when the Listener is outside of the Max Distance. This is because the AudioSource will default to using a Logarithmic Volume Rolloff.

The red Volume node on the right-hand side of the 3D sound Settings graph (1) will show you the volume settings over distance. As you can see in Figure 4.3.9, the volume of the sound will decrease from the minimum to the maximum distance and then remain at 50% volume no matter how far away for the AudioSource the Listener is. If this node is positioned in the bottom right-hand corner in the graph, your sound will not be audible outside of the Maximum Distance (X).

Figure 4.3.9 AudioSource Logarithmic Rolloff Volume (Min and Max Distance Set to 5 and 10 Respectively)

You can fix this issue by setting your Volume Rolloff to Linear (2).

You will see in Figure 4.3.10 that the red Volume node will go to the bottom right of the graph, showing that the volume will be at 0 when at the Max Distance (3).

You can use Linear Rolloff, or if you prefer, you can draw in your own custom curve, moving the Logarithmic rightmost volume node to the bottom right corner of the graph. I would advise listening to both options in-game and deciding which you prefer for each AudioSource.

Figure 4.3.10 AudioSource Linear Rolloff Volume (Min and Max Distance Set to 5 and 10 Respectively)

Blending between 2D and 3D

I have described 2D non-positional sounds and 3D positional sounds as being separate elements, but as you may have noticed, the ‘Spatial Blend’ parameter is a slider allowing for a blend between the two rather than a discrete binary choice between A and B.

You may initially be thinking, ‘but why would you want to be able to transition between 2D and 3D using a single AudioSource?’

Imagine in a game that there is a loud sound source at the far end of the level, such as a massive waterfall. The player is tasked with travelling through the level and approaching the base of this waterfall. Ideally you would like the waterfall to sound positional, panning around as the player looks in various directions, or 3D when far away from it. When up close to the waterfall, you do not want the changes in the player’s view to affect volume or panning, or at least make sure these are much less pronounced or non-positional 2D. This is one situation in which you may want to blend between 2D and 3D sound spatialisation, depending upon the player’s distance from the sound source.

The best way to accomplish this is to draw in a custom curve changing the Spatial Blend parameter setting. When at the topmost part of the graph, the AudioSource will be 3D and at the bottom 2D. You can see in Figure 4.3.11, viewing the distance along the X axis of the graph, that the Green Spatial Blend parameter is fully 3D from 0–20 distance and fully 2D between 80–100 distance. It will begin to transition between 3D and 2D as the player and Listener move between these points.

Have a look and listen to the SFX_AMB_2D/3D_Lake GameObject in the Viking Village Audio Scene to see how useful this can be for certain sounds.

This can be found using the following Hierarchy path:

Audio > 2D/3D Ambience Spatial Blended > SFX_AMB_2D/3D_Lake

Figure 4.3.11 AudioSource Customised Spatial Blend Curve

You can then move the placed AudioSource where you want in the gameworld by dragging the three blue, green, and red axes, like the simple shapes covered in Chapter 1 using the Move Tool (2).

Figure 4.3.12 Placed AudioSource in Viking Village Level

To Play or not to Play

The best way to learn how all the parameters of the AudioSource Component will affect the sound and each other is to place them in the gameworld, start playing the game, and experiment. Unity has a very useful feature that allows you to adjust the parameters of a GameObject while the game is running i.e. in Play Mode. This is immensely useful as you can get instant feedback on how changing various parameters will affect the sound of the game. When playing the game if the mouse is being used to control the character view press the Esc key on your keyboard to make the mouse cursor visible.

The only downside to adjusting the mix when the game is playing is that Unity will reset all of the Component values back to their original values before the game was playing i.e. when exiting Play Mode and re-entering Edit Mode. The reason Unity resets all parameters back to their starting values instead of saving every change like you would expect in a DAW is that all of these parameters can potentially be changed by code when the game is running. Resetting the values and parameters when exiting Play Mode means the game will always start from a default known state.

There is, however, a useful workaround for this issue. When the game is in Play Mode, you can right click on the AudioSource. Alternatively, click the three vertical dots icon in the top right and select Copy Component. When you stop the game playing you can then right click on the same Component and Paste Component Values.

Make sure you DO NOT click on Paste Component as New, or you will add in an additional AudioSource Component alongside the existing one.

This copy/paste function is very useful as it saves you having to write down or screenshot values to manually update them when you have stopped the game running, exited Play Mode, and re-entered Edit Mode. The major downside to this approach, however, is that you can only copy one set of Component values at a time.

Figure 4.3.13 Copy/Paste AudioSource Parameter Settings

50 Shades of Play

If the changes you have made within the AudioSource seem to Disappear, check that you have not added these while accidentally using the Pause Function in Edit Mode or thinking you are in Edit Mode when you are actually in Play Mode.

Every Unity developer, myself included, has on several occasions wasted more time than they’d like to admit adjusting parameters across multiple Components, while accidentally having Pause enabled while in Play Mode. When pressing the Play button to then test these changes, all the work you have done in this mode then is automatically and irretrievably lost as the Components revert back to default Edit Mode values. This WILL happen to you at some point; the key is to recognise the cause of the issue and attempt to ensure it does not happen on a regular basis.

To help combat this, Unity has introduced an option to apply a tint or shade to the screen while in Play Mode.

Left click on the Edit Menu along the top and then select Preferences and left click on the Colors Tab.

Figure 4.3.14 Play Mode Colour Tint (Optional)

You can now use the Color Wheel to select a tint that will be applied when in Play Mode. Make sure that you do not change the A or Alpha value, as this will make all the text in the panels become lighter. This effect makes the text much harder or impossible to read.

5 quick tips

You can actually replace audio files in Unity using the Windows Explorer/Apple Finder method while Unity is in Play Mode. This can save time if it takes a few minutes to play up to a certain point in the game.

You can copy and paste settings from any Component in Unity, not just the AudioSource.

When playing the game and looking at the AudioSource in the Inspector Panel, if you are inside the Max Distance, the current Listener position can be seen on the 3D Sound Settings AudioSource graph.

You can modify many parameters such as Spatial Blend on the AudioSource over distance by adding in your own additional nodes in the 3D Sound Settings graph.

If you cannot hear your AudioSources, make sure Unity is in Play Mode and not Edit Mode. Also check you have Enabled Play On Awake, Loop, and the AudioSource GameObject is Enabled. If this issue persists on a 3D sound, try temporarily changing the Spatial Blend parameter to 2D to check if the AudioSource has accidentally been positioned in a different location than you expect.

Additional Tip

Many of the practical projects included with this book use the mouse to control the view of the camera when Unity is in Play Mode/playing the game. By default, your mouse cursor will not be visible. If you want to make the mouse cursor visible, press the Esc key on your keyboard to make the mouse cursor appear on screen. This will then allow you to adjust any parameters on any of the Panel Windows, such as the AudioSource Component in the Inspector, or to select various GameObjects in the Hierarchy.

Chapter 4 practical tasks

The practical task for Chapter 3 was to get some hands-on experience creating Audio Assets and using the skills learned in the previous chapter to design sounds. You will now be implementing these within a playable Viking-themed game level.

While appropriate and creative sound design is always important to focus on during Game Development, don’t forget to correctly name and organise your Audio Assets when creating and importing them into Unity.

The practical task for Chapter 4 is to practice placing AudioSources in Unity. Be sure to experiment with all of the various AudioSource parameters to see how they affect the sound when getting closer and further away from the sound source.

I have downloaded the project folder for a small 3D level created by Unity called Viking Village from the Unity Asset Store and modified it to work with Unity version 2019.4.20f1.

This project folder can be found under the DLC resources for Chapter 4.

Although this project may look visually similar to the version available from the Unity Asset Store, it has a number of code adjustments ‘under the hood’ to customise this to work specifically with the Unity version used within this book.

You have been provided with:

One zipped/compressed folder containing the main project titled Chapter 4 Viking Village Silent (which, as its name suggests, is currently silent except for footsteps). This is the project into which you should implement your own audio.

One zipped/compressed folder containing the Chapter 4 Viking Village Audio. You can download and open this if you want to view or listen to the original Audio Implementation for reference or inspiration.

This Unity Project is first person, and it has already been set up to use the common keyboard buttons W, A, S, D, or the directional keys to move the character around the level. The mouse can be used to move the first-person camera view left/right and up/down to look around.

Open the project folder in Unity HUB and select to open it in Unity. When the project has finished importing all the Assets, navigate to the Scenes folder and double click on the Viking Village Silent Scene file to load it.

Import the Audio Assets you have made for the previous chapter practical task and create and place several diegetic AudioSources around the gameworld over objects such as the flaming torches or large moving wooden cranes. Don’t forget to also implement some non-diegetic 2D ambience such as wind!

You can also practice replacing the existing footstep Audio Assets with your own updated audio files.

Remember to assign your imported AudioClips from the Project Panel into the AudioClip parameter of the AudioSource. Also remember to enable the Loop and Play On Awake parameters.

Focus on how the Audio Listener distance from the AudioSource changes the volume and panning relative to the AudioSources, and how the various parameter settings affect how you perceive the volume and localisation (direction) of the audio.

The reason for introducing ambience and providing this small game level with very limited gameplay rather than immediately working on the final project is that you will likely want to experiment and learn how to implement 2D and 3D in a small and easier to manage setting. I often find in my own work on professional games that it is best to experiment with new techniques or features in a smaller setting, learning and optimising my workflow before then rolling out these changes to the entire game.

When starting a new project, I would also initially attempt to get the ambience and footsteps completed first. It can be tempting to initially go straight for the big, attention-grabbing sounds, but in my experience, getting a good balance in terms of frequency and volume between these two elements will help not only to ‘set the scene’ within the level and quite literally connect your playable character to the world, but also to balance the gameplay sounds when adding these in one by one later in development now that you have your ambience and footsteps to use as a reference.

After completing adding in your own ambience for this level and replacing the existing footsteps, you will have gained a large number of skills and familiarity with sound design and implementation for interactive video games. This experience will enable you to refine your workflow, as you will hopefully have learned valuable lessons from experimentation or smaller mistakes you make on this level before then getting stuck into the main project in a few chapters time.

Figure 4.5.1 Image from Viking Village Scene

Optional additional task

Consider returning to this level when you have completed the main game project to review your work and consider having another go at this level now you have much more experience.

5 Understanding basic game mechanics and generic Unity tools

DOI: 10.4324/9781003055167-5

As audio is present throughout the entirety of a game, a competent Sound Designer must have a basic understanding of many other departments’ workflows to effectively implement audio across a wide variety of systems. This includes but is not limited to some cursory programming, animation, and game design knowledge.

This chapter will focus on learning more about common individual processes such as how the Components and physics engine work together. Although the information in this chapter may not seem immediately relevant to audio, these tools and techniques will be used in later chapters to add in a dialogue system, interactive music system and to interactively change ambient SFX throughout the game level. When completing the Chapter 5 practical task, you will see first-hand how this knowledge will enable you to add in your own audio to various game mechanics.

Game audio offers an opportunity to connect a listener to a virtual world in a way that other media can never achieve: interactivity. Games respond to a player’s input and the best ones do it so successfully that they create a deep and emotional connection; imagining ways to amplify this connection is the fundamental principle of game sound design. Understanding how game mechanics work will allow you to develop interesting audio implementations that use inputs from the game engine to control and modulate sound.

The most basic implementation is a ‘sound trigger’ which plays sound in response to a change in game state e.g. play a jump sound when a character jumps. Even simple actions such as this can be made more interesting by adding modulation – for example in A Short Hike (2019) as a character climbs the sound effects pitch bend upwards matching the progress up the face of the cliff. This adds to the fun, whimsical aesthetic as well as providing dynamic feedback that responds to the player’s input. Clever little tricks like this add character and reinforce a game’s aesthetic. Every sound is an opportunity just waiting for you to discover an interesting implementation. Play the game, immerse yourself in the mechanics and start experimenting.

Simon Leary-Wood
(Senior Audio Programmer, Rockstar Games)

What is a game mechanic?

A game mechanic is specific input from the player that causes a set response from the system, or basically the rules of the game. This can range in complexity from a simple example such as the jump mechanic in Super Mario Bros (1985), enabling Mario to make the treacherous journey to another castle hoping he can rescue Princess Peach, to more complex examples such as the Bullet Bill power-up in the Mario Kart series. This later example from the more recent series of the game uses a combination of intricate systems such as pathing, VFX, and collision to transform your character into Bullet Bill and then travel at a high speed along the track, knocking over any other character unlucky enough to get in the way.

The techniques you will learn in this chapter will begin to build up an understanding of how different elements of the game engine work together to create the mechanics that define how the game will play. This information will then be put into a specific audio perspective when discussing how to integrate your own audio into the final game project in later chapters.

Camera

Quickly reviewing from Chapter 1, when working in Unity you may find that you need to position the Game Camera in the Game Panel to clearly see the GameObjects on screen. This can be accomplished in two ways.

The first way is when using the Game Panel view to highlight the Camera GameObject in the Hierarchy Panel, and use the Transform and Rotate tools to manually position it in the Scene.

The second method is to position the Camera in the Scene Panel using a combination of the Alt button, left mouse button, and the directional arrow keys. Once the Camera GameObject is in position, you can then highlight the camera in the Hierarchy Panel. Select the GameObject menu in the top left and select Align With View.

This will snap the Game View camera to the current view in the Scene Panel.

Figure 5.1.1 GameObject Align with View

Rigidbody Component

A Rigidbody Component is used to add physics simulations to a GameObject. You can add this by left clicking to highlight a GameObject in the Hierarchy Panel; use the Component Menu in the top left to select Physics category and the Rigidbody Component. Alternatively, you can use the Add Component button on the Inspector to search for Rigidbody.

Figure 5.1.2 Add Rigidbody (Method 1)

Warning

DO NOT USE RIGIDBODY 2D – THIS IS A DIFFERENT COMPONENT WITH A DIFFERENT PURPOSE SUCH AS 2D PLATFORMING GAMES OR UI MENUS.

Figure 5.1.3 Add Rigidbody (Method 2)

Start by creating two 3D cube GameObjects, one to act as a floor and one to act as a small cube positioned above the floor to fall on as in Figure 5.1.4.

Figure 5.1.4 Cube Positioned Above ‘Floor’ Cube

If you press the button to enter Play Mode, nothing will happen; both cubes will be suspended in mid-air. Left click to highlight/select the Cube GameObject in the Hierarchy Panel and add in a Rigidbody Component.

Figure 5.1.5 Add in a Rigidbody Component

The Use Gravity checkbox will be on by default; if you press Play now, you will see the small cube will use the gravity system in Unity and fall, passing through the floor.

Box Collider Component

A Box Collider Component is used to make a GameObject solid. You can add this by highlighting a GameObject in the Hierarchy Panel, then using the Component Menu in the top left to select Physics and Box Collider. Alternatively, you can use the Add Component button on the Inspector to search for Box Collider.

Warning

DO NOT USE BOX COLLIDER 2D – THIS IS A DIFFERENT COMPONENT WITH A DIFFERENT PURPOSE SUCH AS UI MENUS.

Figure 5.1.6 Adding a Box Collider Component

Add the Box Collider Component to both the Cube and the Floor GameObjects. Note the Is Trigger checkbox will be Disabled/Unchecked by default when adding in the Box Collider Component.

Figure 5.1.7 Is Trigger Parameter on Box Collider Component

If you now press Play, you will see that the small Cube GameObject will use gravity and fall, landing on the Floor. If you click on the Is Trigger checkbox to activate it, you will now find that the Cube will fall and pass through the Floor GameObject.

The Rigidbody, Gravity and the Box Collider, Is Trigger checkboxes all affect how the GameObjects will interact with the physics system in the world.

The Rigidbody Component will enable the various physics systems and make the GameObject solid

The Gravity Checkbox will allow the GameObject to fall towards the ground

The Is Trigger will allow other GameObjects to pass through

In the final game project, you will see, and implement yourself, different combinations of these Components and parameters. They will be used to construct a dialogue system and a music system and, also, when exploring the existing game mechanics, to investigate how best to add in your own audio within the existing setup.

Modifying Variable Component values

As a Sound Designer, you rarely have to create the game mechanics yourself; this is usually handled by Level Designers or Gameplay Programmers. However, it is very helpful to be able to look at the Components for the Code Assets, also known as Scripts, which make up the mechanics to see how they are operating. This enables you to gather information that can inform your sound design implementation.

While this book does not explicitly focus on writing or reading code, it will look at how you can use code Components indirectly in the Inspector Panel to alter or change the code behaviour without having to directly modify the code yourself.

Quite often programmers will make certain parts of the code on the Inspector Panel available so that other departments, such as Level Designers or Sound Designers, can tweak them without having to directly modify the code themselves. Programmers can also make the code more flexible so it can be reused, repurposed, or adjusted throughout the game.

These adjustable values are referred to as Exposed Parameters or Public Variables. For the remainder of this book, they may be referred to simply as Variables. They will appear on the Inspector Panel as part of the individual Script’s Components.

In Figure 5.1.8, I have created a script called Example_Script. I have also created a public variable called Example Variable Name.

Figure 5.1.8 Example Script with Example Variable Name

As you can see, this variable is using a number value of 0. The code inside the script will allow you to overwrite this value on the Inspector, thus changing the value that has been assigned to the variable Example Variable Name.

The variable names are set by the person who writes the code; they can be called whatever that person decides is most appropriate. Generally, they will be named in a sensible way, so that you will know what part of the code they refer to.

I would advise you at this point to download the Chapter 5 Example Project from the additional downloadable resources. Uncompress/unzip this and add it to the Unity HUB the same way you did for the Viking Village Project in the previous chapter.

Open up the Chapter 5 Example Project and follow along with the remaining examples in this chapter. Using the Project Panel, begin by double left clicking on the 2. Variable – Countdown Timer Scene found on the Root (topmost folder) of the Assets tab to open the Scene file.

Figure 5.1.9 Chapter 5 Example Project 2. Variable – Countdown Timer Scene

The following example is a script for a Countdown_Timer. When Unity is in Play Mode, this script will count down from the Count Down From value in the Inspector to zero, displaying the number on screen.

When reaching zero, it will then disable the Countdown Timer Variable GameObject and the GUI GameObject. Disabling these GameObjects will stop the countdown timer from continuing to count down into negative numbers and remove the graphical number from the screen respectively.

The Explosion SFX Audio Source variable will Enable the attached Explosion AudioSource GameObject AudioSource, thus playing a sound accompanying the timer when it reaches zero.

The Explosion VFX variable will also enable the attached Explosion VFX GameObject causing the visual explosion effect to appear on screen.

Figure 5.1.10 Countdown_Timer Script Variables

A variable has been created called Count Down From and has been set to a value of 3. The code inside this script will count down from the value entered in the text box to zero. If you were to press Play in Unity and observe the Count Down From variable in the Inspector, you would see the value of the variable count down in real time from 3 to just below zero.

The reason the countdown value does not stop directly on the number zero is because the various events Enabling and Disabling GameObjects described earlier have been coded to occur when the value reaches less than zero. For reference, it is possible to write the code to have the timer stop exactly on zero, but for the purposes of keeping the code as simple as possible in this example, this functionality has been omitted.

The following is the only code example in this entire book; it has been included to demonstrate what the public variables are effectively doing to modify the code.

The green text beginning with ‘//’ has been added to explain briefly the function of each line of the code. You can see on line 8 of this script that the variable name countDownFrom is set to 3.0f or ‘=’ equal to 3.0 or the number 3. If you change the value of the variable on the Inspector from 3 to any number you choose, you are effectively overwriting the value of the code inside the script from the default value of 3.0f to whatever number you have typed in the text box on the Inspector.

Try this out for yourself. Select the Countdown Timer Variable GameObject in the Hierarchy, pick any whole number between 1 and 100, and type it into the text box to the right of the Count Down From Variable on the Inspector. Now, press the Play button and watch in the Game Panel and on the Inspector how the number you have just entered is now the new value Unity will begin to count down from.

In effect, Unity has just modified the Script for you by replacing the value of 3.0f on line 8 of the code example with the number you have typed into the Count Down From Variable on the Inspector.

Figure 5.1.11 Example Code from Countdown_Timer Script

Figure 5.1.12 Count Down from Variable

Using public variables instead of ‘hardcoding’ or using private variables for the values inside the script enables you to modify the timer value and reuse the same script in various parts of the game with unique values each time you use the script.

Variables can be used for a number of different types of GameObjects, including Graphical Text to display on screen, animations, art models, and of course audio.

The Variable Text (GUI) has been added to the Countdown_Timer script. The code linked to this variable will display a number on screen when Unity is in Play Mode. The Text GUI Variable has been created to allow you to assign a GameObject containing a Text Component. This will allow you to set the font used, the size of the text, and its position on screen.

Figure 5.1.13 Text GUI Variable

To assign the GameObject containing the Text Component to the Text GUI Variable, begin by observing the Hierarchy. Locate the Text GameObject, it is as a Child of the Canvas GameObject, which is itself a Child of the GUI GameObject.

Figure 5.1.14 GameObjects Assigned to Countdown_Timer Script

In future when describing the Hierarchy path of Child GameObjects, this will be written as in the following example. The Parent GameObject will be listed first, then each Child GameObject will be listed successively.

To describe the Hierarchy location of the Text GameObject, the Hierarchy path will be written as follows:

Hierarchy path: GUI > Canvas > Text

To assign or add the Text GameObject to the Text GUI Variable, you need to drag and drop the Text GameObject into the box/drop target immediately to the right of the Text GUI Variable.

Practice this by left clicking on the Text (Text) box immediately to the right of the Text GUI Variable to select it. Now, press the delete key on your keyboard to unassign or remove the current link between the Text GameObject and the Text GUI Variable.

Your Countdown_Timer Script in the Inspector should now look like the image in Figure 5.1.15.

Figure 5.1.15 Unassign Text GUI Variable

If you enter Play Mode at this point, you will see New Text will be displayed on screen in the Game Panel and the error message ‘NullReferenceException: Object reference not set to an instance of an object’ will appear in red at the bottom of the Unity editor. This is because the Countdown_Timer script has not been told what to display and the Text GUI Variable has not been assigned a Text GameObject.

To assign the Text GameObject to the Text GUI Variable, begin by left clicking on the Countdown Timer Variable GameObject in the Hierarchy to select it. Next, left click and continue holding down the mouse button on the Text GameObject in the Hierarchy. Move your mouse to hover over the box immediately to the right of the Text GUI Variable in the Inspector that currently reads None (Text). Release the left click and observe that the box that previously read None (Text) will now display Text (Text) as shown in the next image.

Figure 5.1.16 Assign Text GameObject into Text GUI Variable on Countdown_Timer Script

Unity will only let you assign/drag and drop Assets or GameObjects with the required Components into the individual variables. Public variables will explicitly say what kind of Asset they expect. For example, you cannot place an AudioSource or Audio Asset when the Script expects a Text Asset.

In Figure 5.1.17, you can see that the Text GUI Variable expects a (Text) GameObject or Asset to be added to the variable, the AudioClip Asset variable expects an (AudioClip) Asset, the AudioSource Variable expects an (AudioSource) and the GameObject Variable expects a (GameObject).

Figure 5.1.17 Example Script Variable Types

In the previous chapter, you learned that the Play On Awake parameter of the AudioSource will play the AudioClip Asset as soon as the level starts if the GameObject is Enabled. If you look in the Hierarchy for the Scene, you will notice that the Explosion AudioSource GameObject has been Turned Off/Disabled and Play On Awake has been Checked On.

Figure 5.1.18 Explosion AudioSource GameObject Parameters

The Countdown_Timer script, using this code example, has been assigned and coded to Enable the Explosion AudioSource GameObject attached to the Explosion SFX Audio Source Variable when the timer reaches zero on line 23 of the script. You can observe this code working when entering Play Mode if you look at the Enable/Disable checkbox directly to the left of the GameObject name in the Inspector. When the timer reaches zero, a tick will appear in this checkbox as the code is Enabling the AudioSource GameObject.

By taking advantage of the ‘Play On Awake’ feature, this allows the AudioSource to Enable and play the sound when required, in this case when the timer reaches zero, provided the AudioSource GameObject is Disabled when starting the level.

If the Explosion AudioSource GameObject had been Enabled when entering Play Mode, the explosion SFX would play straight away; in addition to this, when the timer reaches zero the AudioSource will not play the SFX because the GameObject has already been activated. In essence, you will not see (or hear) a change when Enabling a currently Enabled GameObject using code. You can try this out yourself if you change the status of the Explosion AudioSource GameObject to be Enabled while in Edit Mode before then entering Play Mode. Just remember to set this back to Disabled when you are back in Edit Mode.

Variables are not only extremely powerful in that they can modify various GameObjects performing actions like Enabling or Disabling, but if a piece of code is written with well thought-out variables, it can also make the script extremely flexible in its application without requiring direct modifications to the code.

Using the Project Panel, double left click on the 3. Variable – Countdown Timer Expanded Scene to open the Scene file to follow along with the next examples.

When selecting the Countdown Timer Expanded GameObject, you will see that a script called Countdown_Timer_Expanded has been added in the Inspector. This script features a number of very flexible variables, which I will explain next. You will also see that a number of GameObjects have been created in the Hierarchy.

Figure 5.1.19 Countdown Timer Expanded Script and GameObjects

The Count Down From Variable will, as in the previous example, be the number of seconds the timer will begin at.

The Enable Audio Source 3 When Timer Reaches Variable will enable the Audio Source 3 GameObject assigned in the following variable. This happens when the Count Down From value reaches/counts down to the value typed into the Enable Audio Source 3 When Timer Reaches textbox.

The Enable Audio Source 2 When Timer Reaches and Enable Audio Source 1 When Timer Reaches Variables likewise Enable the assigned Audio Source GameObject when the Count Down From value reaches the value entered in the textbox.

If you press Play at this point, you will see the countdown will begin at 5 and will trigger AudioSource 3 when three seconds remain, trigger AudioSource 2 with two seconds remaining, and AudioSource 1 with one second remaining. The final Explosion AudioSource will play an Explosion SFX when the timer reaches zero, much like in the previous Countdown_Timer script. AudioSources 1, 2, and 3 have an AudioClip which will have a female computerised voice saying a number corresponding with what is shown on screen in the Game Panel.

With the addition of the extra variables, this script can easily be modified to enable the AudioSource GameObjects to trigger when the timer reaches any values you choose. You could then also change the AudioClips present in the associated AudioSources to play any audio file you have imported into the project.

In the example project, change the following variables:

The Count Down From: Change this to 10

Trigger Seconds AudioSource 3: Change this to 5

Trigger Seconds AudioSource 2: Change this to 3

Next, change the Audio Assets for the following AudioSource GameObjects:

These additional Audio Assets can be found using the following path in the Project Panel:

Assets > Content > Audio Assets

AudioSource 3: Change the AudioClip from DX_Three to DX_Five

AudioSource 2: Change the AudioClip from DX_Two to DX_Three

Now press Play in Unity and see how you have changed the behaviour of the Countdown script to count down from 10, and to play an AudioClip saying ‘Five’ when the countdown reaches 5 and ‘Three’ when the countdown reaches 3.

Changing the functionality of the project to make the script activate AudioSources at specified times and say a corresponding number may not immediately seem to have a practical application within a real game. However, this script could very easily be adapted to form the basis of a dialogue hint system.

This script could be set up to activate when the player reaches a new area of the game and is confronted with a puzzle they must solve. Instead of the AudioSources being used to state the time remaining for the countdown, they could instead be used to play an audio file containing dialogue written to act as a hint.

For example, if the Count Down From value was changed to a value of 600 seconds or 10 minutes, then AudioSource 3 could be used for the first hint, which may be quite subtle, such as ‘Hey, the path is blocked, there must be a way around it’. This would be set to activate when the timer reaches 420 seconds remaining or after the player has explored the area for 3 minutes.

AudioSource 2 may then be set to activate when the timer reaches 240 seconds remaining; this could potentially play a second dialogue hint that is more direct, such as ‘I wonder if we could use this lever for something?’

Finally, if the player is still unable to solve the puzzle, they are likely to be quite frustrated at this point in the game. AudioSource 1 could be set up to play a third and final dialogue hint with 30 seconds remaining. This hint could be much more explicit and give the player the exact instructions they need to solve the puzzle, such as ‘I think the lever needs to be placed under the boulder to move it out of the way’.

Using this hints example, the Countdown_Timer_Expanded script could be added as an individual Component to a number of GameObjects related to various puzzles across the game. Using the variables provided, you could add in individual dialogue lines for every hint and set unique or ‘variable’ timers to set various different time requirements depending upon how complex each individual puzzle may be and how long it may take for an average player to become frustrated and require a hint.

Well-written code will not only perform complex functions, but will also, and just as importantly, be written in a flexible way. This will allow other members of the development team to tweak how the code will function on an individual basis themselves, rather than relying on a programmer to manually change values from inside the script.

The disadvantage of not being able to code yourself is that if you wanted to change the existing functionality by playing an additional sound or making the timer count up rather than down, then you would have to request this functionality from a programmer. These skills can be developed over time after finishing this book, but currently without them you are in some ways limited to the behaviour you are able to influence by relying on modifying existing variables and pre-existing code, using these tools in creative ways to accomplish your goals.

Prefabs

A Prefab is a GameObject that you can store in your project, which can contain several GameObjects, Components, and Assets within it. A Prefab can be thought of as a template which can then be copied and pasted by the Games Designers in the Scene View or even automatically by Unity when the game is running.

One major advantage to using Prefabs is they allow you to quickly and easily duplicate a collection of GameObjects between Scenes when Unity is in Edit Mode, or to spawn in a GameObject (including all Child GameObjects into the level) when Unity is in Play Mode.

An example of spawning in Prefab templates such as this would be the generic enemies in a beat ’em up game such as Streets of Rage (1991). An example of using Prefabs as a template to copy and paste GameObjects between scenes or levels would be the rings in a Sonic game (1991). If working on this game yourself, you would not want to have to go through each ring in a Sonic game individually and manually add the SFX and VFX when the ring is collected. As you can probably imagine, this would take an extraordinarily long time.

It is much simpler to create one template or Prefab and have the Level Designer place this knowing all associated SFX and VFX are attached to this one Prefab Asset. This somewhat automates the setup. The added advantage of using a Prefab is that you can modify one Prefab Asset and have this automatically populate or push the changes across all of the linked Prefabs in the game.

In the case of Sonic’s rings, I’m sure you could imagine how powerful and time saving this type of tool can be if you needed to modify the pickup sound for the rings late into development of the game. Without using Prefabs, you would have to go back through all of the rings to update the sounds or tweak the volume balance manually. If this change was required a week before the game is due to be released, it would be an impossible task for a single person to complete; using Prefabs, this change could be done in 30 seconds.

You can think about Unity’s structure in the following way:

You have one Unity Project.

You can have several Scenes or levels inside that one project.

You can have multiple Prefabs in each Scene.

The Prefabs are also capable of being used across multiple Scenes, like the Sonic ring example.

How to create a Prefab

You can create a Prefab by dragging a GameObject from the Hierarchy into the Project Panel. The new Prefab will take on the name of the GameObject. The GameObject in the Hierarchy will also turn blue to signify that it is now linked to a Prefab Asset.

Figure 5.2.1 Creating Prefab

Using the Project Panel, double left click on the 4. Prefabs Scene to open the Scene file to follow along with the next examples.

Locate the Cube Prefab Asset in the Project Panel using the following path:

Assets > Content > Prefabs

If you left click on the Cube Prefab in the Project Panel Assets folder, the Inspector Panel will show all the Components for the selected Prefab’s GameObject/s. In this example, this will include the Transform Component, Box Collider, Mesh Render, and Rigidbody Component. All of the settings from each Component will be saved in their current parameter settings; all uses of the Prefab within each Scene will also share these same parameter settings.

Figure 5.2.2 Prefab Components

Left click and hold down the mouse button, then move your mouse into the Scene view and release the mouse button to drag and drop a copy of the Cube Prefab into the game level. You will also now notice that this action has created a new GameObject called Cube in the Hierarchy. Repeat this step another two times to add a total of three Cube Prefabs to the level; if needed, use the Move tool to position these roughly, as shown in Figure 5.2.3.

Figure 5.2.3 Adding Prefabs to Scene

At this point, if you press the Play button, all three of the Cube GameObjects will fall onto the Floor GameObject.

Modifying Prefab variables

You will need to modify existing Prefabs in the final game project used for various identical GameObjects (such as the enemies), so it is important you understand the various methods to accomplish this. Although this may initially seem confusing or complex, through practice using Unity, this will become second nature very quickly.

From an audio perspective, using Prefabs means you will only have to set up one version of each enemy. Any sounds or AudioSources you modify will then populate this change automatically to all identical enemies in the game. This will save you an enormous amount of time that can be better spent on fun, creative tasks, rather than what is basically repetitive data entry.

Using the Chapter 5 Example Project, create a new Scene and follow the steps outlined earlier to add in the Cubes and create a Prefab. Select the Cube Prefab Asset in the Project Panel by left clicking on it. You can add in a Physics Material to the Material Variable on the Box Collider Component on the Cube Prefab. This will make the Cube bounce after hitting the ‘floor’ GameObject and can be accomplished in two different ways. There is no major workflow benefit between them, so use whichever approach you prefer.

Left click on the small round icon just to the right of the Material Variable box on the Box Collider Component. This will search your entire Assets folder for Assets compatible with this variable; in this particular example, it will be Physics Materials.

A popup window will appear, and you can then double click on the Bounce_Material name to add it to the variable.

Alternatively, you can drag and drop the Bounce_Material from the following Assets Panel subfolder directly into the Material Variable on the Box Collider Component:

Assets > Content > Physics Materials

When added correctly, it will appear in the Inspector as in Figure 5.2.4. For reference, I have clicked on the dropdown to hide the individual parameters of the Transform, Cube (Mesh Filter), and Mesh Rendered Components to reduce the vertical height of the Inspector for screenshot purposes.

Figure 5.2.4 Adding Bounce Material to Cube Prefab Box Collider Material Parameter

Now play the game level and watch the Cubes happily bounce up and down when hitting the floor. When completing the example above, please ensure you create your new Scene within the DLC Chapter 5 Example Project as this contains the Bounce_Material asset. This asset has been specifically added within this example project and will not be present when creating a new 3D project yourself.

Saving Prefab modifications

There are two main ways to modify a Prefab and have this change affect all instances of that Prefab in the game.

One method is to select the Prefab Asset in the Project Panel and directly change one of the Components. This was the method you used in the previous step to make the Cubes bounce by adding in the Bounce_Material Physics Material.

The other is to select any of the instances of the Prefab in the Hierarchy. At the top of the Inspector, you will see that three new buttons related to Prefabs will have appeared.

Figure 5.2.5 Prefab Inspector Buttons

The Open button will open up the Prefab in a temporary scene, enabling you to change the structure of the Hierarchy.

The Select button will select the Prefab Asset in the Project Panel.

The Overrides button will allow you to apply any changes you have made to this specific GameObject in the Hierarchy to all instances of the Prefab across the game.

Using the Hierarchy, select any of the Cube GameObjects; select the Bounce_Material by left clicking on it and press the delete key to remove the Bounce_Material. If you now left click the Overrides button, you will be able to see all of the changed GameObjects, Components, and values/variables that you have modified. In your particular case, if you left click on Box Collider, you can show the modification removing the Physics Material.

Figure 5.2.6 Prefab Overrides

Clicking Apply All will apply all of these changes to the Prefab Asset and make all instances of this Prefab also have these same changes.

Clicking Revert All will remove all of your changes and set all changed GameObjects, Components, and changes values/variables back to how the Prefab is currently configured in the Project Panel.

Figure 5.2.7 Prefab Override Revert All and Apply All Buttons

If you select Apply All to remove the Bounce_Material Physics Material, this change will be replicated in the Box Collider Component on all three Cubes; you will see all three Cubes fall and not bounce off the Floor GameObject when you play the game. This change is replicated or ‘pushed’ to all instances of the Prefab, even though you only made the modification on a single GameObject.

You can make changes to instances of the Prefab in the Hierarchy individually. This may be useful if you want to add a voice-over SFX to one specific enemy and not have this change apply to all similar enemies in the game. Any Components that differ from the ‘Base’ value of the Prefab will be shown in bold.

Figure 5.2.8 Individual Changes to Prefabs in Inspector

Ensure you add the Bounce_Material back onto the Cube Prefab before moving onto the next example.

To better replicate the kinds of changes you will be applying in a real game project, we will add in an AudioSource to play a SFX when the Cubes bounce off the floor, and a Script to play this AudioSource when the event happens.

Pick one of the Cubes within the Hierarchy and left click to select it.

Right click on the same Cube and add in a new AudioSource.

Figure 5.2.9 Adding AudioSource to Cube

Add in the Bounce SFX Asset to the AudioClip parameter on the AudioSource. The SFX Asset is already in the project and can be found using the following Project Panel path:

Assets > Content > Audio Assets

In addition to this, ensure Play On Awake is disabled (not checked) and that the Spatial Blend parameter is set to 3D so the audio plays back positionally.

Figure 5.2.10 AudioSource Added as Child of Cube Prefab GameObject

Next, select the Parent Cube Prefab GameObject and add in the BounceSFXScript by searching for it by name after clicking the Add Components button.

Assign the AudioSource you have just created to the BounceAudiosource variable on the BounceSFX Script. Start by left clicking and holding down the mouse button on the AudioSource GameObject in the Hierarchy. With the left mouse button still held, drag this over the drop target for the Bounce AudioSource in the Inspector and release the mouse button. This dragging and dropping action has now assigned the AudioSource with the variable on the script. The code within the script will now play the AudioClip using the settings specified within the AudioSource parameters when the box bounces off the floor.

Figure 5.2.11 Adding and Assigning AudioSource

At this point, if you play the game, you should hear a bounce SFX when the Cube you have just modified touches the Floor GameObject. If you find that the volume of this is too quiet or you cannot hear the SFX, check that you have followed all the steps provided thus far. If these are correct, then consider increasing the Min Distance parameter on the AudioSource from 1 to 100.

You have now successfully created an AudioSource, assigned an AudioClip with the correct settings, added in the script required to play the AudioSource when the Cube bounces, and assigned this AudioSource to the variable. Well done. There is one problem, though. At the moment, only one of the three Cubes is playing a SFX when it bounces off the Floor GameObject. You could of course replicate the steps you have performed up to this point on the remaining two Cubes, but it will be much quicker to just apply this change to the Prefab and have Unity automatically update the other Cube Prefabs in the project.

Use the Hierarchy or click on the Cube Prefab in the scene with the SFX implementation, then click the Overrides button on the Inspector.

Confirm that the Bounce SFX script and an AudioSource have been added and then press the Apply All button.

Figure 5.2.12 Using Overrides “Apply All” Button

Now play the game and confirm that all Cube Prefabs are making a sound every time they bounce on the floor.

There is one last feature with Prefabs that we need to cover before the Chapter 5 Practical Task.

If you select the new AudioSource GameObject you have just created on any of the Cube Prefabs, press the delete key to attempt to delete it. If you try to delete a Child GameObject or rearrange the order of the Child GameObjects within a Prefab, the message seen in Figure 5.2.13 will appear on screen.

Figure 5.2.13 Cannot Restructure Prefab Message

This message is letting you know that you are unable to directly modify the structure of an existing Prefab. To remove or rearrange Child GameObjects, you will need to press the Open Prefab button. This will load the Prefab in its own temporary Scene and allow you to make any change to the structure of the Prefab that you want.

When you have finished, you can press the arrow icon in the top left of the Hierarchy to save your changes to the Prefab and return you to the Unity Scene you are working on.

Figure 5.2.14 Save and Close Prefab

You do need to be aware that modifying the Prefabs directly using this method will automatically and instantly apply all of the changes you have just made to the Prefab as soon as you press the left arrow icon, as indicated in the image in Figure 5.2.14. This method effectively bypasses the Overrides option and will not allow you to choose between Applying or Reverting your changes.

Open up the Cube Prefab by double left clicking on the Cube Prefab in the Project Panel Assets folder, or select the Cube GameObject in the Hierarchy and press the Open button on the Inspector. Delete the AudioSource by left clicking on it and pressing the delete key on your keyboard, then remove the Bounce SFX Script. Save this change by clicking on the arrow icon as shown in the previous image.

To test this has worked correctly, play the game one last time to check if all the Cubes no longer play a SFX when they bounce.

5 quick tips

If you are adding a new Child GameObject, or updating an existing variable on a Prefab, then it is often quicker to use the Overwrite function.

If you need to reorganise or delete a Child GameObject from a Prefab, it is often quicker to open the Prefab to make modifications.

When adding Components, beginning to type the name of the Component or script will act as a search function and may mean you don’t have to type the complete name. Over the course of an entire project, this will save you a considerable amount of time.

On certain scripts such as the Countdown, you can see the variable number updating in the Inspector while the game is running. You will also see parameters on all Components changing while the game is playing, if they have been coded to do so.

If relying on other members of the team for coding tasks, it is best to think about what you want the sound to do and, equally importantly, not to do, before requesting audio support for additional audio variables. The more experience with Game Development you gain, the easier this process becomes, enabling you to better anticipate any potential issues.

Chapter 5 practical task solutions

There is one Unity Project to download for the practical task.

This project is named Chapter 5 Practical Task and can be found in the downloadable resources.

You will need to uncompress and add this project into the Unity HUB before opening it to begin the task.

The countdown is not helping!

First, ensure you have followed along with the downloadable Chapter 5 Example project to modify the various Scenes adjusting Variables, Components, and Prefabs.

Your mission, should you choose to accept it

Download and open the Chapter 5 Practical Task Project from the DLC folder. Use the information gained about the game mechanics tools covered so far to modify the Unity Scenes included in the project.

When first opening the project, a Tutorial window will appear; it is your choice if you wish to complete the tutorial in the Unity Editor and then close the Panel or to immediately close the window and begin the task. To close this window, click on the three vertical dots in the top right-hand corner of the Tutorials Panel and select Close Tab.

Figure 5.3.1 Close Tutorials Tab

If the level appears to be flat (2D), please ensure you disable the 2D view option in the Scene Panel.

Figure 5.3.2 Scene 2D Button

Your goal is to enable the turquoise Player character to walk from the starting position into the dark blue circle, triggering a celebration.

Figure 5.3.3 Level End Point

Typical W, A, S, and D and directional arrow keys apply for movement controls.

After reaching the end point at the dark blue circle, you will need to take Unity out of Play Mode and back into Edit Mode to select the next Scene. The Scene files for each level/part can be found in the Assets > Scenes folder.

There are four sections in this project with corresponding Scene names. These should be completed in sequential order as they increase in difficulty. The specific instructions for this task have been left quite vague by design. A very important skill within Game Development is the ability to solve problems using your own knowledge, rather than always relying on step-by-step instructions. However, if you find that you struggle to complete the tasks, solutions can be found on the following pages.

Download and open the Chapter 5 Practical Task Unity Project, which can be found in the downloadable resources.

This task is designed to test your understanding and problem solving to your limits. If you initially struggle with the task, I would advise you read back through the chapter before looking at the solutions provided next. By successfully completing the following tasks, this is proof that you have a firm grasp and understanding of the Unity principles covered so far. Up to this point in the book we have been looking at Components or Unity techniques individually. From this point forward, we will be exploring how these Components can be used in conjunction with one another to create more complex game mechanics. Ensuring you have a firm grasp over the material so far will help you quickly understand more advanced topics that will come later on in the book without becoming overwhelmed.

You should not add, delete, or move any of the GameObjects or Prefabs in Task 1, 2, or 3 (this is cheating). In Part 4, you will be required to add and then position additional Prefabs.

You also Do Not need to modify, add, or remove any code in this project to complete the tasks successfully.

Task 1 Mission Accepted (this level will self-destruct in ten seconds)

Your mission, if you choose to accept it, is to reach the extraction point in time.

Task 2 Bring on the Laser Maze

You build games in Unity using GameObjects and Components. Learn about how adding a Rigidbody Component to your GameObject adds and influences Physics behaviour.

Task 3 Bring on Bullet Time

Develop your Component knowledge further as you learn about variable values and how they affect gameplay. Can you slow down the polygon-eating zombie and door closing in time to escape?

Task 4 Mission (Almost) Accomplished

Prefabs are the secret sauce behind all Unity games. In this lesson, you’ll learn about building them as you ramp up your knowledge and escape the final laser death trap!

The additional Prefabs can be found using the following path in the Assets folder:

Assets > Task 4 Additional Prefabs

When you finish all of the previous tasks, there is an optional additional task

As you have noticed, audio has already been implemented into the Mechanics for these tutorial levels.

In Chapters 2, 3, and 4, I covered how to create Audio Assets, import/replace existing Audio Assets in Unity, and mix the sound using the AudioSource Component.

Go through each of the GameObjects in each tutorial to find the AudioSources that are used for the Audio Implementation. Don’t forget to add in some 2D ambience and music.

Your mission is to create your own Audio Assets and import them into the Project Panel. You should then replace the Audio Assets that are currently added to each AudioClip parameter for the AudioSources or variables on GameObjects.

This task has elements that are significantly harder than any other task in this book. I do not expect you will be able to replace the SFX Asset used within every game mechanic as it requires knowledge of Unity systems that have not yet been explored in this book. I advise spending as much time with this as you are comfortable taking. When you have completed as much of this ‘Impossible Mission’ as you are able, then feel free to read through the solutions to double check your answers.

Chapter 5 practical task solutions

You can use the following instructions to help you solve the practical tasks.

In the additional downloadable resources, download the Chapter 5 Project Solved Unity Project from the DLC if you want to see the completed task inside of Unity.

Ensure that you save your Editor changes before pressing Play for all solutions to make sure the Components do not reset back to default values.

Task 1 Solved – Mission Accepted (this level will self-destruct in ten seconds)

Begin by going to the root of the Assets folder and double clicking on the Task 1 Scene file to open it.

Your task is to use the W, A, S, D or directional arrow keys to move the light blue playable character to stand on the dark blue circle within five seconds.

Press the Play button in Unity

Guide the character into the blue circle near the centre of the level within 10 seconds

Task 1 optional replace audio task

1. Create an AudioSource for music. Create your Looping Audio Asset and import it into your project.
Add your Audio Asset to the AudioClip parameter of the AudioSource and set it to 2D, Loop, and Play On Awake.

2. Remove the existing AudioSource used for Ambience. This is located as a Child of the Environment Parent GameObject and is named AmbientAudio. Add in an AudioSource for ambience, create your looping Audio Asset, and import it into your project. Add your Audio Asset to the AudioClip parameter of the AudioSource and set it to 2D, Loop, and Play On Awake.

3.1 To update the Win/Achievement SFX used when reaching the goal, you could just replace the existing Audio Asset using the Windows Explorer/Apple Finder method, but that would technically be cheating. To find where this has been added in the project, click on the Goal Prefab in the Hierarchy to select it.

3.2 Open the Prefab by clicking the Open button near the top of the Inspector.

Figure 5.4.1 Goal Open Prefab Button

3.3 Look down the Inspector for the Goal (Script) Component.

Figure 5.4.2 Goal Script AudioSource Variable

3.4 Double left click on the WinAudio (AudioSource) variable to have Unity automatically select the AudioSource in the Hierarchy.

Figure 5.4.3 WinAudio GameObject AudioSource

3.5 Replace the existing Achievement AudioClip with one you have created yourself, and feel free to change the volume and pitch parameters to balance this with any other ambience or music you have added.

4.1 To update the SFX that plays along with the VFX fireworks when you reach the Blue Circle, click on the Goal Prefab in the Hierarchy to select it.

4.2 Open the Prefab by clicking the Open button near the top of the Inspector.

Figure 5.4.4 Goal Prefab Open

4.3. Select the Child Fireworks GameObject located inside the Parent Goal GameObject.

Figure 5.4.5 Fireworks GameObject AudioSource

4.4 Scroll down the Inspector to find the AudioSource and replace the existing Fireworks AudioClip.

4.5 To update the Beeping SFX that corresponds with the timer running out, select the Environment GameObject in the Hierarchy and use the following path to find the AudioSource:

Environment > Countdown Explosion > Beep AudioSource

Figure 5.4.6 Beep GameObject AudioSource

4.6 Replace the AudioClip in the AudioSource with one of your own Audio Assets.

5.1 To update the Explosion SFX when the timer reaches zero, select the Environment GameObject in the Hierarchy and use the following path to find the AudioSource:

Environment > Countdown Explosion > Explosion AudioSource

Figure 5.4.7 Explosion GameObject AudioSource

5.2 Replace the AudioClip in the AudioSource with one of your own sounds

5.3 To update the dialogue currently saying ‘Mission Failed’ when the timer reaches zero, select the Environment GameObject in the Hierarchy and use the following path to find the AudioSource:

Environment > Countdown Explosion > GUI Mission Failed > DX_ Mission_Failed

Figure 5.4.8 DX_Mission_Failed GameObject AudioSource

5.4 Replace the AudioClip in the AudioSource with your own dialogue Audio Asset file.

Task 2 Solved – Bring on the Laser Maze

Begin by going to the root of the Assets folder and double clicking on the Task 2 – Bring on the Laser Maze Scene file to open it.

Your goal is to make the box with the 1 printed on the top, fall when standing on the green triangle in order to block the first death laser. You then need to make the box with the 2 printed on it solid so it can be pushed over, blocking the second death laser. Finally, sprint to the Blue Circle to complete the level.

1.1 You can either left click on the Box with the 1 printed on it using the Scene Panel, or click on the Box1 GameObject in the Hierarchy.

1.2 Scroll to the bottom of the Inspector and press the Add Component button, then add a Rigidbody Component. The Rigidbody Component will allow the Box to use the Physics Gravity system in Unity and fall to the floor.

Figure 5.5.1 Add Rigidbody Component to Box1 GameObject

2.1 You can either left click on the Box with the 2 printed on it using the Scene Panel, or click on the Box2 GameObject in the Hierarchy.

2.2 Scroll to the bottom of the Inspector and press the Add Component button, then add a Rigidbody Component. The Rigidbody Component will also make the Box solid, allowing it to be pushed by the Robotic Arm.

3. Press the Play button in Unity.

4. Guide the character into the Blue Circle near the centre of the level.

Task 2 optional replace audio task

1. Again remove the existing AmbientAudio GameObject and add in an AudioSource for music and another AudioSource for ambience. At this point, consider revisiting the Task 1 Scene and creating a Prefab from your existing ambience and music AudioSources to add to the level. This will save you having to create and set up individual AudioSources for each part of the task.

2.1 To replace the sound for the red laser closest to the player, when beginning the level you can click on the laser in the Scene View or use the following Hierarchy path:

Environment > Lasers > LaserLine

2.2 Scroll down in the Inspector to find the AudioSource and replace the ‘Laser’ AudioClip.

2.3 The laser closest to the second box can be found using the same Hierarchy path directly under the first LaserLine GameObject.

Figure 5.5.2 LaserLine GameObject AudioSource

3.1 To replace the SFX when standing on the Green Triangle that triggers the first Box falling, you can either click on the Triangle using the Scene Panel or click on the SwitchTriangle GameObject in the Hierarchy.

Figure 5.5.3 SwitchTriangle Prefab Open

3.2 You may have also spotted that this GameObject is a Prefab. Again, I would advise you to change the AudioClip within the Prefab by opening it to apply the change to all instances where the Green Triangle Switch is used across the various Scenes.

3.3 Scroll down in the Inspector to locate the Switch Material Highlighter (Script) Component.

Figure 5.5.4 Switch Material Highlighter and SwitchAudio AudioSource Variable

3.4 Double left click on the SwitchAudio (AudioSource) Variable to have Unity Automatically select the AudioSource in the Hierarchy.

Figure 5.5.5 SwitchAudio GameObject AudioSource

3.5 Replace the existing ‘Marker’ AudioClip with one you have created yourself.

4.1 To replace the SFX when Box 1 hits the floor, you can either click on the Box 1 using the Scene Panel, or click on the Box1 GameObject in the Hierarchy.

4.2 Scroll down in the Inspector to the Play Audio On Collision (Script) Component and replace the existing Cube Drop New AudioClip in the Clip Variable located directly above the AudioSource.

Figure 5.5.6 Box1 Play Audio On Collision Script Variables

4.3 Double left click on the AudioSource located in the Play Audio On Collision (Script) Component, to have Unity automatically select the AudioSource in the Hierarchy if you want to adjust the volume or pitch controls for mixing. DO NOT add an AudioClip directly into the AudioSource as this will play immediately when starting to play the level and be replaced by the AudioClip within the Play Audio On Collision (Script) Component when the Box hits the floor anyway.

Figure 5.5.7 Box1 Audio GameObject AudioSource

5.1 To replace the SFX when Box 2 slides along the floor, you can either click on the Box 2 using the Scene Panel, or click on the Box2 GameObject in the Hierarchy.

5.2 Scroll down in the inspector to the Play Audio On Collision (Script) Component and replace the existing Cube Floor AudioClip in the Clip Variable located directly above the AudioSource.

Figure 5.5.8 Box2 Play Audio On Collision Script Variables

5.3 If you want to adjust the volume or pitch controls for mixing, double left click on the AudioSource located in the Play Audio On Collision (Script) Component to have Unity automatically select the AudioSource in the Hierarchy. DO NOT add an AudioClip directly into the AudioSource as this will play immediately when starting to play the level and be replaced by the AudioClip within the Play Audio On Collision (Script) Component when the Box2 GameObject is pushed across the floor.

Figure 5.5.9 Box2 Audio GameObject AudioSource

6.1 Discovering where to replace the SFX when standing on the Red Rectangle that triggers the Robotic Arm is actually quite tricky to find and requires understanding of systems you have not looked at in Unity yet. You may have initially identified the AudioSource that is used for this sound. If not, it can be found by either clicking on the Robotic Arm using the Scene Panel or clicking on the RoboticArm GameObject in the Hierarchy. You may have found that replacing the None (AudioClip) on the AudioSource with your own Audio Asset caused this to immediately play when starting the level, and that the original SFX still continues to play when the Robotic Arm moves forward.

Figure 5.6.1 RoboticArm Prefab Open

6.2 You may have also spotted that this GameObject is a Prefab. Again, I would advise you to change the AudioClip in the Prefab to apply the change to all instances where the Robotic Arm is used across the various Scenes.

6.3 To actually locate where the AudioClip has been implemented, you need to double left click on the RoboticArm attached to the Controller Variable. This will open up the Animator Panel (which has not been covered yet).

Figure 5.6.2 RoboticArm GameObject Animator

6.4 If you then left click on the Push button found in this Animator Panel and view the Inspector, you will now see the AudioClip Variable for the Audio Asset. You can now replace this ‘Lever’ AudioClip with your own sound. When you are finished, right click on the Animator Panel to close this window tab.

Figure 5.6.3 Close Animator Panel

6.5 Now that you finally have your own AudioClip implemented, return to select the RoboticArm GameObject and scroll down in the Inspector to locate the AudioSource Component. Your settings for the AudioSource should match those in Figure 5.6.4 to make the sound play as intended. Finally, close the Prefab, saving your changes, and playtest the game.

Figure 5.6.4 RoboticArm GameObject AudioSource Parameters

Task 3 Solved – Bring on Bullet Time

Begin by going to the root of the Assets folder and double clicking on the Task 3 – Bring on Bullet Time Scene file to open it.

Your aim is to slow down the Enemy enough that you can sneak past without being caught and then hold the Automatic Doors open long enough to make it to the Blue Circle.

1.1 You can either left click on the Enemy within the game level using the Scene Panel or left click on the Enemy GameObject in the Hierarchy.

1.2 Scroll down in the Inspector to locate the Nav Mesh Agent Component, adjust the Speed Variable, currently set to 30, and change this to 5 to slow the enemy speed considerably.

Figure 5.7.1 Enemy Prefab Nav Mesh Agent Speed Parameter

2.1 You can either left click on the Gate Doors using the Scene Panel or click on the AutomaticDoors Level 3 GameObject in the Hierarchy.

2.2 Scroll down in the Inspector to locate the Door (Script) Component, adjust the Time Until Close Variable currently set to 0.4 and change this to 12 to slow the door closing speed considerably.

Figure 5.7.2 AutomaticDoors Door Script, Time Until Close Parameter Settings

Task 3 optional replace audio task

1. As in previous Scenes, remove the existing AmbientAudio GameObject. If you have already created a Prefab containing your ambience and music then kudos, add this to your scene and move on to point 2. If not, add in two AudioSources for your ambience and music respectively, assign an AudioClip for each, and set them to 2D, Loop, and Play On Awake.

2. If you have already added sounds to the Prefab for both the Red Rectangle and Green Triangle, then congrats again; feel free to skip ahead to step 3.1. If not, then revisit points 3 and 4 of Task 2 to perform the same functions replacing the AudioClips.

3.1 To replace the sound when the gate is lowered, releasing the Enemy uses a similar method as the RoboticArm in the previous Task 2 Scene.
As with the RoboticArm before, you may have initially identified the AudioSource that is used for this sound. If not, it can be found by either clicking on the Gate in the level using the Scene Panel or clicking on the MazeGate GameObject in the Hierarchy. Again, as before, you may have found that replacing the None (AudioClip) with your own Audio Asset caused this to immediately play when starting the level and that the original SFX still continues to play when the Gate is lowered.

3.2 To actually locate where the AudioClip has been implemented, you need to double left click on the MazeGate attached to the Controller Variable in the Inspector; this will open up the Animator Panel.

Figure 5.7.3 MazeGate GameObject AudioSource

3.3 If you then left click on the GateOpen button found in this Animator Panel and view the Inspector, you will now see the AudioClip Variable for the Audio Asset. You can now replace this Barrier Drop AudioClip with your own sound. When you are finished, right click on the Animator Panel to close this window tab.

Figure 5.7.4 GateOpen Animator Panel

3.4 Now that you finally have your own AudioClip implemented, return to select the MazeGate GameObject and scroll down in the Inspector to locate the AudioSource Component. Ensure your settings for the AudioSource match those in the Figure 5.7.5 to make the sound play as intended.

Figure 5.7.5 MazeGate GameObject AudioSource Parameter Settings

4.1 To replace the sounds for the Enemy vocalisations as it runs back and forth in the level, you can either left click on the Enemy using the Scene Panel, or click on the Enemy GameObject in the Hierarchy.

4.2 Using the Inspector Panel, scroll down to locate the Enemy (Script) Component. Locate the AudioClips section and, if required, press the dropdown button to view the variables, as in Figure 5.7.6. Type the number of SFX variations you have created into the Size Variable to create the required amount of additional AudioClip Variables and then add in your own SFX assets to replace the existing ones.

Figure 5.7.6 Enemy GameObject Enemy Script AudioClips

4.3 To locate the AudioSource these clips use in the Hierarchy, ensure the Enemy GameObject is selected as in Figure 5.7.6 and scroll down to the bottom of the Inspector.

4.4 When you playtest the game and release the Enemy, if the AudioSource is selected you will notice that every time it makes a sound, Unity will randomly pick one of the available AudioClips. When this happens, you will see this new AudioClip swapped into the AudioClip parameter of the AudioSource.

Task 4 Solved – Mission (Almost) accomplished

Begin by going to the root of the Assets folder and double clicking on the Task 4 – Mission (Almost Accomplished) Scene file to open it.

Your goal is to add in a Ramp Prefab, position it as in Figure 5.8.1, and use it to scale the wall. You then need to add in PushableBox Prefab placed in front of the RoboticArm, allowing it to be pushed over and block the laser when standing on the Red Square.

Both of these Prefab Assets can be found using the following path in the Project Panel:

Assets > Prefabs Task 4

Figure 5.8.1 Task 4 Mission (Almost) Accomplished Scene Box and Ramp Prefab Locations

Task 4 optional replace audio task

1. Again, remove the existing AmbientAudio GameObject. If you have already created a Prefab containing your ambience and music, then you’ve hopefully learned how quick it will be to drop this into your level to have a pre-created ambience. Feel free to move onto point 2. If not, then add in two AudioSources for your ambience and music and set them both to 2D, Loop, and Play On Awake.

2. If you have already added sounds to the Prefab for both the Red Rectangle and Green Triangle, then, as before, feel free to skip ahead to step 3. If not, revisit points 3 and 4 of Task 2 to perform the same functions replacing the AudioClips.

3. The door opening sound will need to be replaced. This is because the doors use separate Prefabs, as this one does not need to be adjusted to work correctly. Adding in a sound for this door functions exactly the same as in the previous Scene. The same applies for the PushableBox Prefab with the 3 printed on the top: add in the sounds exactly as you have previously done in the Task 2 Scene.

4. The final sounds to add in for this level are the Robotic Arm sound and the Box Scraping sound, assuming they have not previously been added directly to the Prefab. By this point I’ll bet you’re wishing you just modified the Prefabs the first time to save you repeating the same work.

5.1 To update the dialogue currently saying ‘Mission Accomplished’ when the reaching the final Goal, select the Environment GameObject in the Hierarchy and use the following path to find the AudioSource:

Environment > GUI Mission Accomplished > DX_Mission_ Accomplished

Figure 5.8.2 DX_Mission_Acomplished GameObject AudioSource

5.2 Replace the AudioClip in the AudioSource with your own dialogue

Red light! Green light!

If you’ve made it this far, then well done; the tasks you have just performed replacing all of the existing AudioClips are very similar to the functions required in the final game project you will begin to tackle in the next chapter. If you did find this task very challenging, don’t worry; the step-by-step instructions in the following chapters will guide you through how each and every mechanic in the game works from simple to optional, more complex methods.

6 Set up main game project, creating a project plan and Game Audio Design documentation

DOI: 10.4324/9781003055167-6

This chapter will guide you through downloading and setting up the final game project and ensuring that it runs optimally on your computer. It can also be intimidating beginning with a silent, fully functional game that you need to add all of your own sounds, dialogue, and music to. You will also explore concepts relating to planning how to approach a large project so that it can be broken down into smaller, more easily manageable chunks.

When a new project rears its head and you are contemplating that figurative blank page; the empty project session, first sounds, first ideas – it can be a daunting and paralysing moment – where to start? There is no right way to do this, no wrong way, just finding a door or a window into this world, and using whatever methods you can to get working on those initial ideas. Maybe it all starts for you with building an ambience, filling in the world around the player – or, maybe it starts with a gunshot or a footstep, or a blood curdling scream off-screen … maybe it starts not with sounds, but with structure, with an organized hierarchy, perhaps even a spreadsheet, an initial defined place into which you can throw ideas and start trying sounds out – finding the ports of entry into the project can be difficult- perhaps you need to find your collaborators first. The good news is that you are here, at the beginning, where everything is possible.

Rob Bridgett
(Senior Audio Director), www.sounddesign.org.uk

Downloading and importing main game project

This book will contain a number of additional downloadable resources (some of which you should have already downloaded and made use of for Chapters 1, 4, and 5 practical tasks).

From this point onwards, instead of referring to this as the ‘Main Game Project’, I will refer to this as the Unity 3D GameKit or the 3D GameKit. Please know that these names are interchangeable and refer to the Unity Projects provided in the accompanying Downloadable Content or DLC resources.

In addition, when referring to left clicking and holding to drag and drop a GameObject or Asset into a public variable, I may also refer to this process as adding an Asset or GameObject to a drop target. This shorthand more closely resembles the terminology you are likely to hear when working in a real development studio or when reading online forums or viewing YouTube ‘How To’ videos.

This project is a 3D platformer game in the same vein as Ratchet and Clank, Spyro the Dragon, or Crash Bandicoot game series. It is a modified version of the existing 3D GameKit Project available on the Unity Asset store. The version provided with this book also comes with a number of custom additional Audio Script Components that will enable you to more easily implement your own immersive and dynamic soundscape (and a few smaller design tweaks to turn the gameplay up to 11).

Although this project may look visually similar to the version available from the Unity Asset Store, like the Viking Village project it has a number of adjustments ‘under the hood’ to enable much more control over the audio integration, as explained within the following chapters, and has been customised to work specifically with Unity version 2019.4.20f1.

You have been provided with:

One zipped/compressed folder containing the main project titled 3D GameKit, which is currently silent (3D GameKit Silent Project.zip). This is the project into which you should implement your own audio.

One zipped/compressed folder containing the 3D GameKit game if you want to view or listen to the original Audio Implementation for reference alongside the images within this book (or even just for some inspiration) (3D GameKit With Audio Project.zip).

Importing and opening the final game project

You need to download and unzip/uncompress the Silent 3D GameKit project.

Once uncompressed, open the Unity HUB and left click on the ADD button.

Figure 6.1.1 Adding Project to Unity HUB

Navigate to the folder where you have uncompressed the downloaded project and add the 3D GameKit Silent Project Folder, in a similar way to how you added the Chapter 4 Viking Village Project.

As you can see, the 3D GameKit Silent project has now been added to the list of projects in the Unity HUB. Left click on the name of the project to open it.

Figure 6.1.2 3D GameKit Project Added to Unity HUB

You will find that Unity will perform a simulated import procedure as it is creating all of the required library files for the Unity Project, as the 3D GameKit is considerably larger than the Chapter 4 Viking Village and Chapter 5 Mechanics Project. Depending upon your computer speed, it could take anywhere between 5 and 45 minutes for your computer to perform the import procedure, so you might as well go and put the kettle on.

After the project has been opened for the first time on your current computer, it should then open considerably quicker (approximately less than a minute) when re-opening.

This project has several interconnected Scenes that automatically switch between one another as you play through and complete the various levels within the entire game. To open the first level of the 3D GameKit level, find the Level01 Scene file located within the Scenes folder on the Assets Project Panel; if you want to experience the entire game, double left click on the Start – Front End Scene. Choose and then double left click either of these options to load up the associated Scene file.

Figure 6.1.3 Unity 3D GameKit Scenes

It’s not about if you get knocked down, it’s whether you got back up

Back in Chapter 1, I advised that you ensure you did not have your Unity Project open in an automatic backup system such as Dropbox™, Google Drive™, or One Drive™. In this chapter, I also went through saving the current open scene using either Ctrl + S on PC and Cmd + S on OSX.

It is very important that you DO NOT select the Save As option from the File Menu.

This is because the Scenes within the game have already been set up to transition between one another when completing the level. Saving As will not actually create a backup of the project as you may expect when using a DAW and will actually mean that your New Scene Files will not be linked into the Scene loading system already set up, thus breaking the logical progression of the game.

Unity does not have its own internal backup system like you would expect to find on a DAW. The reason for this is that when producing music, usually only one person will work on a single DAW session/project at one time. In Unity, potentially hundreds of people could be working on different smaller sections or parts of the same project simultaneously. Generally, within Game Development, there tends to be a file Repository system that will contain the Master game project hosted on a server.

A repository is basically a central file storage location. It is used by a Version Control system to store multiple backups of files. While a repository can be configured on a local machine for a single user, it is often stored on an online server, which can be accessed by multiple users.

It enables the individual members of a development team to have a copy of all project files on their computer. In the case of audio, when you add in a new audio file or modify an existing Prefab, you will commit or ‘Push’ your changes to the Master version of the game. Afterwards, you will typically then ‘Pull’ or ‘Update’ your local files to then receive all the changes ‘committed, or pushed’ by the other members of the development team. Using a repository system allows for a number of unique features. First, it allows you to roll back to any older version of a file (much like the Apple TimeMachine Feature); it enables you to ‘revert’ any local changes you have made on your machine (in case you have made a mistake), and most importantly, it allows for multiple people to all simultaneously work on different parts of the same Unity Project.

As each of the most common version control software is set up and used in slightly different methods, this book will not cover how to do this in detail.

As you will presumably be working on your project by yourself, using a full sub-version system such as those listed earlier may be slightly overkill compared with the cost and/or effort of setting this system up and maintaining it.

If you want to investigate this topic further, a few of the most common are:

Apache

BitBucket

Git

Perforce

Tortoise SVN

If you want to use a more straightforward system, I would advise you to regularly copy your entire Unity Project folder along, with any additional DAW projects etc. that you have, and place these onto an external hard drive and cloud-based backup system.

Do this frequently and, depending upon how much free hard drive space you have, keep between three and five of the latest backups. This way, if you somehow accidentally modify your Unity Project, rendering it unplayable/unworkable, you can always just delete the current broken project and copy across your latest backup. This means you should hopefully only need to quickly redo your latest work since last backing up rather than starting from scratch.

I cannot overstate how important it is to keep regular backups. When teaching, I would provide a fully playable silent Unity game project for all students. Every year, without fail, I have had students break the game in various ways, from deleting Prefab Assets, to deleting lighting and textures rendering the entire level in pink. In one case, a student managed to re-import all of the Game Assets over a completed project, effectively deleting all of their implementation work; this caused all the Prefabs and Scene Assets to be returned to their silent default settings and they had to start the project over from the beginning.

You can never have too many backups!

Initially setting up the project

The following Optimising, Mouse Sensitivity, and Controller settings will only need to be modified once when initially setting up the project. These options will customise the 3D GameKit Project to work best on your computer or allow you to select if you wish to also use a controller to play the game.

Optimising performance in the Unity editor

One tip if your computer is struggling to run the game, and you can observe drops in frame rate or performance, is to adjust all the graphical settings for the game. This trades off graphical quality for performance. These settings are not permanent and can be changed at any time.

If you want to capture footage of the game in higher graphical quality, you can work using a low graphical setting and then change to a higher setting if you want to capture some gameplay video featuring your audio.

To change the graphical quality settings, go to the Edit Menu then select Project Settings.

Figure 6.2.1 Unity Project Settings

Select the Quality tab and click on Performance, Balanced, Pretty, Fantastic, or Max to change the quality setting.

Figure 6.2.2 Unity Quality Settings

Tip

You can change these settings while the game is running to quickly compare how the different settings will look. Please remember that the values you set in the Inspector Panel will reset to default when you stop the game playing.

You will then have to redo these settings when the game is not running to save these changes.

Adjusting mouse sensitivity settings

You can adjust the mouse sensitivity settings Unity is using while playing the game in the Game View Panel. This will not adjust your overall mouse sensitivity settings used for your computer or within the Unity while in Edit Mode. This change will only affect the mouse speed settings while the game is running and the mouse is being used to control the camera in the Game View Panel.

Ensure Unity is in Edit Mode i.e. NOT playing the game

Select the CameraRig GameObject that should be visible on the top level of the Hierarchy

Expand the CameraRig GameObject and select the Child KeyboardAndMouseFreeLookRig GameObject in the Hierarchy

Observe the CinemachineFreeLook Component in the Inspector

The value for the Max Speed Variable on the Y and X Axis parameters can be adjusted to reduce or increase the camera speed/sensitivity. Initially, try reducing the current Max Speed values by a factor of 10 to reduce the mouse sensitivity; however, you may find different values that better suit your needs.

Try changing the Y Axis Max Speed Variable value from 10 to 1

Try changing the X Axis Max Speed Variable value from 500 to 50

Select the values that correspond best to your own preferences

Figure 6.2.3 Mouse Movement Sensitivity in Game View

Using keyboard and mouse or controller

You can change the game input method to use a controller if you prefer. I have tested this and confirmed that this will work with an Xbox 360 wired controller, a Wireless Xbox One controller, and a generic controller on a PC using Windows 10. I cannot guarantee that every game controller/pad will work on your computer with this Unity Project; however, in theory, any third party controller should respond to your inputs when the game is running, provided the necessary drivers are installed on your computer operating system.

Select the CameraRig GameObject in the Hierarchy

Left click on the Input Choice setting and change this from the default Keyboard and Mouse option to Controller

Now play the game and check if your controller inputs are registered

You can also optionally invert the controls on the X and Y Axes if you find the Scene View game camera is moving in the ‘wrong’ direction than you are used to using the following checkboxes

Figure 6.2.4 Set Keyboard/Controller Input

Remember to change the Camera settings script for Controller Inputs and Invert Options on the CameraRig GameObject on both Level01 and Level02 Scenes.

Audio Assets

You will notice when comparing the With Audio and Silent projects that I have removed all the original 3D GameKit Audio Assets in the Silent project.

Figure 6.3.1 Silent Audio File in Audio Folder of Project Panel

You can also see in Figure 6.3.1 that I have created and imported an additional audio file called Silent_Audio, located in the 3D GameKit > Audio folder. This, as its name suggests, is a silent, mono audio file. The reason it has been included is that I have attached this silent file to a number of AudioClip and AudioSource Components in the game. You will then replace this with your own Audio Assets in the various AudioSources and Scripts.

You will find that if there is no AudioClip assigned when the sound is triggered, an error will appear in the Console Panel to warn you that an AudioSource has been triggered but has no Audio Asset attached.

You can left click on this message in the Console Panel to have Unity automatically select the GameObject causing the error, allowing you to easily find and then solve the issue.

Figure 6.3.2 Unity Console Error when AudioClips Are Missing/Unassigned

I would advise that you initially leave this Silent_Audio Asset in your project, as it will stop these errors appearing in the Console when working on your game. After you have implemented all of your sounds, you could then remove this Silent_Audio Asset if that’s what you’d prefer. Any audio you may not have implemented yet will appear as an error in the Console Panel when the sound has triggered. As you should have no other errors in your project, this should make it much simpler to locate the audio you may have not implemented yet and resolve the issue.

As shown in Figure 6.3.2, I would also advise enabling the Clear On Play and Collapse functions in the Console Panel by ensuring the respective buttons are lit up. Clear On Play will refresh and remove all existing errors and messages in the Console when Unity goes into Play Mode. Collapse will mean that duplicate errors will not be shown individually; rather, a number will appear on the right-hand side of the Console, letting you know how many times this particular error has happened. As an error may register every frame, this can lead to hundreds of the same error being shown within a few seconds. The Collapse button helps to keep the Console much easier to manage at a glance.

Audio Listener position

Chapter 4 covered the role of the Audio Listener Component. To briefly recap, the Listener can be thought of as the equivalent of your ears in the game. It receives or ‘listens to’ AudioSources that are in the gameworld.

In third-person games such as the 3D Gamekit, one of the first choices the Sound Designer has to make is where to place the Listener.

It can be placed directly on the Main Camera

It can be placed on the playable character in-game

It can sit somewhere in between the Main Camera and playable character

There isn’t a definitive right or wrong answer, as different games choose different options.

This choice does tend to influence the overall sound design and mix decisions.

Currently, the Listener is positioned on the Main Camera, which can be found in the Inspector using the Hierarchy path: CameraRig > CameraBrain.

Figure 6.4.1 Audio Listener Default Location

As the Listener is positioned on the Camera GameObject, this means that you will hear pronounced panning and volume changes to 3D AudioSources when moving the camera position around.

You have the option to change this default setup to move the Listener onto the playable character ‘Ellen’. This will mean that the panning volume changes will be heard from the player character’s perspective, rather than the camera view perspective. The end result is that the panning and volume changes from 3D AudioSources will be less pronounced when moving the camera position around by moving the player.

I would expect, in the majority of similar third-person adventure games, that if the Listener is placed on the camera in the game, the ambient atmospheric sounds would be more prominent within the mix in terms of both volume and frequency content. Conversely, because the ambience is more in focus, the player and enemy sounds should sound more distant, be mixed quieter, and may not require the same level of detail within the sound design. Overall, you would tend to set the Min and Max Distance and Doppler parameters on the 3D AudioSource to account for the fact that the player is able to quickly swing the camera and attached Audio Listener around the player; these should be adjusted so the volume and Doppler changes are not as pronounced.

If you decide to move the Listener and place this on the playable character, I would expect that the player and enemy sounds should be more prominent in the mix compared with the ambience. The footsteps, voice expressions, and combat sounds should likewise have more detail and increased frequency range compared with the ambience. As the player cannot move as quickly around the 3D AudioSources, the volume and panning change between Min and Max Distance parameters typically be set to smaller ranges to produce natural fall off from the AudioSource to the playable character.

I have not specified approximate Min and Max values for either of these settings, as this will be dictated by each individual sound requirements and your overall mix choices. By default, the majority of AudioSources in the Silent 3D GameKit Project have been set to 1 and 20 for Min and Max Distances respectively. This should ensure the sound is audible within the level but far from the optimal settings for each AudioSource. You are encouraged to modify these values when working on your project; if you would like a reference point, these have been adjusted and mixed within the With Audio version of the Project.

To compare the difference between these two approaches, I would advise repeating the previous setup steps and opening the With Audio version of the 3D GameKit Project before following the instructions next to move the Listener to the Main Camera.

Listen carefully to how the relative balance of the mix and panning changes compare between the two approaches.

Moving the listener to the playable character

To move the Listener to the player character, first start by locating the Empty GameObject named ---- AUDIO ----. This should be used to contain all of the audio GameObjects you will add to the project.

I have followed the existing naming/organisation convention and name this Empty GameObject ---- AUDIO ----.

It is also important to ensure that this Parent AUDIO GameObject is located in the centre of the level. Make sure that you note the Transform Position and Rotate values are set to 0 and the Scale values are set to 1.

Figure 6.4.2 ----- AUDIO ----- Empty GameObject

Failure to set the Transform Position, Rotate, and Scale parameters correctly as shown earlier may mean that some of the techniques explained in later pages may not work as you expect or the audio may play from an unexpected location in the level.

From this point on, you are advised to add all Audio-related GameObjects as a Child of this Parent or as instructed to help keep them organised.

Next go to CameraRig > CameraBrain GameObject in the Hierarchy

Find the Audio Listener Component in the Inspector

Left click on the three vertical dot icons indicated by the red square in the image and remove the existing Audio Listener Component

Figure 6.4.3 Removing Existing Audio Listener Component

Return to the empty ---- AUDIO ---- GameObject and add in another Child Empty GameObject. Name this AudioListener and add in an Audio Listener Component and ensure the Transform values are set to 0 for Position and Rotation and 1 for the Scale, as shown in Figure 6.4.4.

Figure 6.4.4 Creating New Empty GameObject and Adding Audio Listener Component

Next, add in the AudioListenerController script.

Figure 6.4.5 Add in Audio Listener Controller Script Component

This script will take the Transform Position from the Ellen (player character) GameObject and apply it to the Listener Transform. It will also take the Transform Rotation from the CameraBrain GameObject and apply it to the Listener Transform.

The Character Variable is where you will attach the Parent Ellen character GameObject. The Camera Variable is where the CameraBrain GameObject will be attached. To achieve this, left click and hold on the Hierarchy Objects to drag them across and drop them into the Inspector Variables as indicated.

Figure 6.4.6 Assigning CameraRig and Ellen GameObject to Audio Listener Controller Script Variables

Now, playtest the game to hear and begin comparing the difference between the two methods.

Please remember, as discussed in Chapter 3, that only one Audio Listener can be active in the Scene at any one time. You will have to pick one of these approaches so that you have only a single Audio Listener.

Please also remember to perform the same Audio Listener setup in both Level01 and Level02!

Audio design documentation and labelling SFX

Game Audio Design Documents

Almost all games will first start out as a Game Design Document (GDD), a long time before any code, game art, or audio has been created. This document will outline the game, including all features, characters etc. that will be present within it.

You will be able to find various examples of professional GDDs by searching on the Internet. Prominent examples to search for include, but are not limited to, the original Diablo PC game (1997), the first BioShock game (2007), and WipeOut (1995).

It’s quite common for various departments to use the GDD as a reference when creating their own design documents. Audio will often have its own design document; this usually outlines whether a particular stylised sound design will be used, how the interactive music system will work, and what the ambience will be comprised of. It will also often include examples of films and other games as reference points. The audio design document is normally then included as a sub-section of the main GDD.

You will find a template called Template Audio Game Design Document for Audio Documentation in the accompanying Chapter 6 DLC materials; this will be presented as a series of questions. You should then answer these questions for yourself, turning them into statements you will use to guide your sound design and to help you formulate a plan for working on the audio for your game.

It is quite common for Game Audio Designers to use a spread sheet to list any sounds that may be required, detailing any descriptive information and listing if the sound has been created, implemented, or mixed. A completed template example can be downloaded from the Chapter 6 DLC folder and is titled 3D GameKit Audio Asset Spreadsheet. This has been set up with the various sound categories and can be modified to include all the sounds you want to add to the game.

If you would prefer to fill this out yourself from scratch, a blank template can also be downloaded from the same location and is named Blank 3D GameKit Audio Asset Spreadsheet.

All of these template documents can be used with either Google Docs/Sheets or Microsoft Word/Excel. All Google/Microsoft documents are identical in content and format.

Typical Game Audio workflow process

When working on a professional game, it is very unlikely that the art, code, and animations will be completed before you begin to add in the audio. This is because all developers from every department will need to finish the game at the same time. If a games studio waited until the game was fully functional and complete before starting to add in the audio, this would potentially add a considerable delay to the release of the game.

There is, however, an established process or workflow that is equally applicable to a finished game like the 3D GameKit Project, or a game that is being developed by all members of a development team simultaneously.

Figure 6.5.1 Game Audio Workflow Processes

Concept

At this time, the game will often not be completed to a playable standard. Concept refers to the initial stages of game pre-production where the Sound Designer will begin constructing the audio design document. They may also create an initial soundscape featuring sections of audio or temporary sounds to help refine the sound design style that would best suit the project.

Spotting

When the game is playable, or the level is at least partially constructed, the Sound Designer will play or look at the game and begin making a list of all of the Audio Assets required. This list refers to the Audio Asset Tracker document provided; the Sound Designer will begin filling this out with the required information about the planned Audio Assets.

Asset Creation

This stage refers to the sound design process, including using the Audio Asset Tracker to then begin creating the sound Assets defined within it. This stage also covers everything from going out to record audio on location such as ambience, vehicles, or even dialogue voice-over, to the sound design process inside of your DAW and Wave Editor. In essence, it refers to the creation of the audio files before they are imported into Unity.

Implementation

This stage involves importing the audio files into Unity and would also include tasks such as creating the AudioSource GameObjects, or anything to do with the process involving making the sounds actually play within Unity.

Mixing

This stage refers to the adjusting of the various parameters to control how the sound will play back. This would include setting appropriate volume, pitch, and spatial processing values on the AudioSource Components.

Testing

This stage is after the sound has been created, implemented, and mixed. It would involve the Sound Designer checking and confirming that all of the previous stages sound and work as intended. Specifically, the Sound Designer will check that the player is not able to cause any unexpected behaviour or that the sound works in all areas of the game. This testing process will also be carried out by a separate Quality Assurance, or QA department. QA’s main priority is to playtest the game and ensure that all mechanics function correctly, and that all art, animation, and audio has been included across the entire game.

The QA department will not typically offer feedback specifically on the creative side of sound design regarding specific sounds or processing; this feedback will typically be offered by a more senior member of the audio team. The QA department will not usually be trained Audio Engineers and will be more concerned about the general functionality of the audio or missing sound effects than providing critical feedback on the mix.

QA will also specifically play the game in unusual ways to ensure that the customer who eventually buys the game is not able to exploit, crash, or otherwise break the game by performing an unexpected action. In audio terms, this could be checking that the player is not able to hear overlapping dialogue and that the subtitles match the audio files across all languages. They will also check that the audio settings function as intended to allow the player to change the balance of music, dialogue, and SFX or that the footsteps sound appropriate for each surface in the game.

The Asset Creation, Implementation, Mixing, and Testing process will run in a continuous, simultaneous loop throughout development.

Figure 6.5.2 Game Audio Process Including Testing

After either yourself or the QA department has tested the game, depending upon the issue that is discovered, this could include going back as far as the Asset Creation stage if a game mechanic is identified as not yet having audio. You might go back to the Implementation stage, if the issue relates to a sound or audio mechanic not playing back correctly. If a sound is identified as being too loud, too quiet, or using incorrect Spatial Blend settings, you would go straight to the Mixing stage. After the issue has been fixed, it will then enter the Testing stage again, first with the Sound Designer and then again to be confirmed as fixed by the QA department if discovered by them.

The examples in the previous paragraph list a few of the most common issues identified for each stage. Potentially, any area of the game may be identified as having a potential issue. The fix for this could be very simple, such as adding in a sound for a mechanic or ambience. It could also be something much more involved relating to a complex set of systems or mechanics, such as the interactive music not working as intended in very specific circumstances.

As I’m assuming you will not have a dedicated QA department yourself when working on your project, try to thoroughly test your work and, if possible, see if you can recruit some friends or family to play your game project to help you identify any potential issues you may have missed yourself.

When working on a project, it is very easy to fall into the habit of taking the quickest or shortest route through a game level. Someone fresh to the game or level will likely play much more slowly and methodically, and in doing this, they may uncover issues you are unaware of.

5 quick tips

ou may find that as your 3D GameKit Project increases in size when you begin adding in your audio files and more advanced implementation. You may then have to reduce the Quality Settings down an additional step if you notice performance issues with your computer.

There are several video presentations and ‘making of’ articles, interviews, and videos for games available to view on the internet. Look at a few similar games for inspiration or ideas for the audio on your own game.

When testing the game to check your own work, try to not just play the game as you would when typically playing a game. Try to play using a variety of play styles, from going very slowly through the level interacting with everything and fully exploring all areas, to attempting to speed-run through it and skip as many unnecessary objectives as possible.

When identifying a complex issue, it can be very helpful to write out a series of steps you took to encounter this. An example would be: ‘Loaded directly in Level01, jumped across the gap/ledge to the main area, didn’t collect the staff weapon and allowed the first group of enemies to kill Ellen/playable character’. Then describe the issue with the audio, such as the music not changing correctly.

It is called development for a reason; games do typically develop and change from the initial documentation throughout the production process. If you find that an initial idea, concept, or theme you had wanted to use during the planning stage is not working out as you expect, don’t feel constrained by your original plan. Many games change dramatically, not just directly in terms of audio but also art style, gameplay mechanics, or even the entire premise of the game, and that will inevitably have knock-on effects and influence for the audio. The planning documents are there as a guide to help you during the production process; they can and often are adapted and updated whenever the ideas or needs for the project develop. This can happen at any time from initial concepts and prototypes to the finished playable project or even after release as a downloadable patch or update.

Chapter 6 practical tasks

The practical task is to download, set up, and then play through the 3D GameKit Project.

It is your choice if you wish to play through the silent version of the project first to form your own initial options and maintain a fresh perspective, or if you would prefer to hear a version already containing audio.

Next, download and fill out the audio design documentation from the Chapter 6 DLC folder. This will help you think about and plan how audio will be used within the project.

Download and begin filling out the Audio Assets spreadsheet from the same Chapter 6 DLC folder to compile a list of required Audio Assets after playing through the game. A blank and partially completed version of the Audio Assets Spread sheet is also available in the Chapter 6 DLC. If you do use this completed version, you will likely still want to add to the initial outline within this for your own project.

If you have not done so already, please download and import the 3D GameKit With Audio Project. Use this to then experiment with the various Audio Listener setup options and choose the one that you prefer to use for your own Silent project.

7 Trigger Areas and Reverb Zones

DOI: 10.4324/9781003055167-7

In this chapter, you will learn to use more complex parts of game engine systems. You will begin to use a combination of the techniques covered in previous lessons to analyse more complex Components and learn how these can be used specifically for audio to interactively control GameObjects and specific Components depending on the player’s position in the gameworld.

This will involve linking a number of systems together using a variety of Scripts and game engine functions.

As previously stated in other lessons, Game Development is highly dependent upon different areas of the game engine interacting with each other to produce game mechanics. These mechanics are then used to define the gameplay.

As a Sound Designer, it is not typically in your remit to actually create the game mechanics. However, it is vital that you have a fairly comprehensive understanding of the tools commonly used in game design to know where, in an existing mechanic, your audio-specific GameObjects should be created. The most obvious example is triggering a sound to play at the right time in the game and to play back from the correct location. Trigger Areas can also be used whenever the player has reached a location of the level, such as using a different reverb preset when inside a cave, or switching the ambience when traveling from inside to outside a room.

Trigger Areas

Trigger Areas work using collision to detect when a GameObject such as the playable character has entered, is within, or leaves a certain area of the gameworld. This will then allow you to turn on or off different AudioSources used for ambience, music, and dialogue, to name a few uses of Trigger Areas specifically for audio.

Collision is a term that is used when two GameObjects touch each other or collide in the game. This makes up the basic framework for a large number of mechanics in games and can be used to trigger audio in a number of different ways, expanding upon the simple mechanics covered in Chapter 5. This could include a character or enemy’s foot colliding with the floor, a bullet impacting on a surface to produce a sound, or a punch connecting with another character and triggering a corresponding SFX.

This type of tool makes up a large number of game mechanics. For example, horror games such as the Resident Evil or Dead Space franchises often make use of jump scares to elicit a reaction from the player. The player may be tasked with travelling down a dark, narrow, twisting corridor; as they turn a corner, an enemy could suddenly materialise out of the shadows, accompanied by a loud piercing SFX or short musical phrase.

One effective method of accomplishing this type of location-based event is to use Trigger Areas.

Unity will be set up so that when the player walks over a certain part of the level, an event such as a jump scare will be triggered.

Trigger Areas are also an incredibly useful tool for Sound Designers to turn GameObjects such as AudioSources on and off when standing inside a room, but they can also be used in more creative ways.

There are many more creative uses for Trigger Areas in relation to audio. They can be combined with any number of other script functions to play a sound or interactively and dynamically modify an AudioSource parameter when standing inside the Trigger Area.

Collider Components

You can implement Trigger Areas by first creating an Empty GameObject in the Hierarchy. Next, add a Collider Component to this GameObject, using the Add Component button in the Inspector. You can choose to use a Box, Circle, or Cylinder-shaped collider GameObject. I personally find the Box Collider shape to be most useful in the vast majority of situations.

Figure 7.1.1 Adding Collider Component

DO NOT use the 2D colliders, as these are set up to work in 2D games or UI menus. The projects provided with this book and concepts discussed relate to 3D games!

After you have added this Component, you can move the GameObject where you need it to be in the level. Next, form the Collider to the desired shape by adjusting the X, Y, and Z Size parameters in the Inspector. Alternatively, you can click on the Edit Collider button and then left click and hold the edges of the Collider to reduce or increase the size along a single axis.

Figure 7.1.2 Box Collider Edit Collider

Figure 7.1.3 Box Collider in Scene View

If you cannot see this green outline in the Scene View Panel when your Collider GameObject is selected in the Hierarchy, please check that you have the Gizmos button activated on the Scene Panel.

If you were to play the game at this point, you would notice that no GameObjects are able to pass inside of the Trigger Area, they would be stopped due to an invisible wall, also known as solid collision. You need to ensure that you have activated the Is Trigger parameter in the Inspector Panel on your Collider; this will allow GameObjects such as the player or enemies to freely pass through the collision.

Figure 7.1.4 Box Collider in Scene View

The following pages describe how several Trigger Areas have been created. They will focus on several methods by which Trigger Areas can be implemented.

In the Level01 scene, I have chosen to use the Trigger Areas to activate an AudioSource that will play a singular low-pitched sound when the player reaches the stone circle in front of the Grenadier door.

Figure 7.1.5 Level01 Boss Door Stone Circle Trigger Collider in Scene View

This is just one example of how Trigger Areas can be used to control the audio based upon where the playable character currently is within the level. Using the following steps, you will be able to recreate, then adapt this example for use however you see fit within your own level, to change any GameObject or AudioSource parameters you choose.

At this point you may wish to open the With Audio project; you will find a GameObject named Trigger Example – Boss Door Stone Circle in the following Hierarchy path:

Level01 > Audio > Trigger Areas > Trigger Example – Boss Door Stone Circle

InteractOnTrigger script

Next, you will add in an InteractOnTrigger script to control what happens to the assigned GameObjects when the playable character enters or leaves the Trigger Area.

Figure 7.1.6 InteractOnTrigger Script Component

This Component can be added in the Inspector by typing in its name after pressing the Add Components button, or by dragging and dropping it into the Inspector from the following Project Assets path folder:

Assets > 3DGameKit > Scripts > Game > Core

This script will initially have a Layers Variable with a drop-down menu; left click on this and set it to Nothing to deselect all the existing layers, then click the button again and set this to only the Player Layer.

By setting the Layers parameter to Player, you are effectively making sure that the only GameObjects the Collider will detect entering or exiting it is the playable character called ‘Ellen.’ This is important, as you will add in a number of Trigger Areas across various levels to create an interactive and dynamic soundscape. You would not usually want the enemies to be able to walk into these Trigger Areas, causing a line of dialogue to play, a change in the music, or activation of reverb parameters in a specific room as shown in later examples.

Figure 7.1.7 InteractOnTrigger Layer Parameter

The code inside the InteractOnTrigger script uses a Unity function called Layers to allow game developers to easily group sets of GameObjects together. This InteractOnTrigger script has been coded to only activate when in contact with the player-controlled Ellen character. If you have a look at the Ellen GameObject, you can see it has been set to the Layer ‘Player’.

Figure 7.1.8 Ellen GameObject Layer Setting (Player)

Using this Player Layer identifies the Ellen GameObject as belonging to the Player Layer group. Similarly, each of the enemies have been grouped together under the Enemies Layer.

Figure 7.1.9 Chomper GameObject Layer Setting (Enemy)

Figure 7.1.10 Grenadier GameObject Layer Setting (Enemy)

Layers are used to group together various GameObjects. This grouping technique allows the code system in Unity to affect multiple GameObjects set to the same Layer, without requiring each GameObject to be manually assigned using public variables. This can save a considerable amount of time while the game is being developed. For example, by using Layers in Unity, code can be written to change the behaviour of all the enemies or art within the game at once, without requiring a public variable list of GameObjects to be manually and continually updated.

The other advantage of using Layers efficiently is that they can increase the performance of the game. Technically, all GameObjects with Colliders could detect if any other GameObject is currently touching or colliding with them. This, however, would require an enormous amount of processing power that could be put to much better use.

If you need Unity to check if a Trigger Area you have created is colliding or touching another GameObject, then you need to manually set the Layer of that GameObject to the Collider Layer in the Inspector.

To assign a GameObject to a specific Layer, select the GameObject in the Hierarchy and observe the Layers option near the top of the Inspector.

Figure 7.1.11 Layer Parameter Button in Inspector

Left click on the dropdown and select Layer number 28: Collider.

Figure 7.1.12 Assigning the Collider Using the Inspector

You DO NOT need to set the Layer parameter for AudioSources or other GameObjects you create.

This step is only required on the GameObjects using a Collider Component and the InteractOnTrigger script. However, if you do not assign the GameObjects with the Collider and InteractOnTrigger script to 28: Collider, nothing will happen when the playable character walks through the Trigger Area.

I created the AudioSource GameObject I wanted to Enable as a Child GameObject of the Level01 > Audio > Ambience SFX GameObject

I have named this BossDoorStoneCircleBoom

Set the BossDoorStoneCircleBoom AudioSource GameObject to Disabled

Add in the LVL01_Boss_Door_Stone_Circle Audio Asset

Set this to play back spatially as 2D

Activate the Play On Awake parameter

Figure 7.1.13 BossDoorStoneCircleBoom GameObject AudioSource

Next, the BossDoorStoneCircleBoom AudioSource GameObject will be assigned to Enable when the playable character walks into the Sphere Collider using the InteractOnTrigger script. As the BossDoorStoneCircleBoom AudioSource has been set to Play On Awake, this will cause the AudioSource to begin playing the attached Audio Asset when it has been Enabled by the InteractOnTrigger script. This event is triggered to happen when the player walks inside or enters the Collider.

Highlight the Trigger Example – Boss Door Stone Circle GameObject in the Hierarchy and view the Inspector Panel using the following Hierarchy path in the With Audio project:

Level01 > Audio > Ambience SFX > BossDoorStoneCircleBoom

The On Enter () parameter will show what GameObjects have been assigned to then perform an action when the player walks into the Box Collider. Likewise, the On Exit () parameter will show what GameObjects have been assigned to then perform an action when the playable character exits or leaves the Box Collider.

Both On Enter and On Exit will display List Is Empty as no GameObjects have currently been assigned.

To assign the GameObject to the On Enter parameter, click the small + symbol as indicated in Figure 7.1.14. This will add in a variable that reads None (Object).

Figure 7.1.14 Adding On Enter () Event to InteractOnTrigger script

Next left click and continue to hold the BossDoorStoneCircleBoom GameObject. Move your mouse over the None (Object) Variable and release the mouse click to drag and drop the BossDoorStoneCircleBoom GameObject to assign it to the On Enter portion of the InteractOnTrigger script.

You will now see the None (Object) will now show the name of the BossDoorStoneCircleBoom GameObject.

You can now left click on the No Function dropdown menu to select what you want to happen to this GameObject when the player enters the Box Collider.

In this example, I have selected the GameObject category and the SetActive (bool) function.

Figure 7.1.15 Assigning BossDoorStoneCircleBoom GameObject to On Enter () Event and Setting Function to SetActive (bool)

Selecting this option will replace No Function with GameObject.SetActive and create a small checkbox directly under the GameObject.SetActive name.

GameObject.SetActive is the code command to control the Enabled or Disabled status of the GameObject currently assigned. Left clicking to add a tick to the checkbox tells the code to Enable or Activate the assigned GameObject.

Figure 7.1.16 InteractOnTrigger, On Enter () Event, Complete Parameter Settings

While the game is running, you will actually be able to see the script adding a tick into the Enable/Disable checkbox for the BossDoorStoneCircleBoom GameObject when the playable character enters the Sphere Collider area. Play the Scene and watch this for yourself by selecting the BossDoorStoneCircleBoom GameObject in the Hierarchy and observing the tick appearing the checkbox at the top of the Inspector as the Ellen playable character enters the Sphere Collider.

Figure 7.1.17 BossDoorStoneCircleBoom GameObject Enable During Play

There are a number of alternative functions that can be activated or changed on an assigned GameObject or the Components within the Inspector beyond just Enabling or Disabling the GameObject.

Select the Trigger Example – Boss Door Stone Circle Trigger Area GameObject in the Hierarchy

Left Click on the + symbol at the bottom of the On Enter function to add in an additional function variable

Assign the BossDoorStoneCircleBoom GameObject to the variable drop target by dragging and dropping it

Left click on No Function and select AudioSource

Select float pitch

Observe directly under AudioSource.Pitch a public variable has appeared

Replace the number 1 with the number 0.9

Select the BossDoorStoneCircleBoom GameObject and observe that the Pitch parameter on the AudioSource is set to 1 in the Inspector

Press Play in Unity to start the game

Make the playable character walk through Box Collider/Trigger Area

Observe the Pitch parameter on the AudioSource changing from 1 to 0.9

Figure 7.1.18 Adding AudioSource Pitch Control to InteractOnTrigger Script

If you have the BossDoorStoneCircleBoom AudioSource visible in the Inspector, you will not only see the GameObject become Enabled but also that the Pitch parameter has now been changed and set to a value of 0.9.

In this case, I have not chosen to alter the Pitch parameter for any specific creative reason as this could also easily be set directly on the AudioSource. This example is meant to demonstrate that using this script, you can alter any parameter on any Component by assigning it to the InteractOnTrigger script and making the Ellen character walk through the Collider.

Try this yourself with a looping AudioSource by creating a Trigger Area and changing the Volume or Pitch parameter when the player enters the Trigger Area.

Figure 7.1.19 shows a list of adjustable AudioSource controls for changing Pitch, Volume, Loops, Mutes, Bypassing Effects etc. There are many creative ways you can change the parameters of an AudioSource when using Trigger Areas. When additional advanced topics such as Unity’s built-in audio effects have been covered later in this book, consider revisiting this chapter to think of ways to dynamically change the various parameters of the effects as the character walks through the levels.

Figure 7.1.19 All Possible AudioSource Parameter Settings Available Using InteractOnTrigger Script

The previous example described how to create a Trigger Area that functions like a one-way switch; as soon as the player walks through the Trigger Area an event happens, such as activating a music change. Then, no matter how many times the player walks back and forth entering or exiting the Collider, no further action will happen.

In this scenario, I have created Trigger Areas to switch between two reverb settings on the right hand side of the level after collecting the Staff weapon.

This change will happen when the player walks into the small area containing the first-floor switch that will open the large door blocking the playable character’s path.

I will cover how to add in and set up an Audio Reverb Zone in the next section of the book.

It is your choice if you would prefer to skip this section for now and learn about the Audio Reverb Zone Component first, before then returning to this section.

Figure 7.1.20 Alcove Section Level01

If you play the game using the Level01 Scene, jump over the ledge/gap and pick up the Staff Weapon

Press the attack button to swing the staff and listen to the reverb characteristics at this point in the level

Now, walk up towards the large stone door blocking the path, turn right, and enter the alcove area

When inside this area again, press the attack button to swing the staff and listen to the change in the reverb characteristics

This space should sound vastly different to the area outside the alcove; if you struggle to hear the difference in reverb characteristics changing, a technique is explained later in this chapter that should make this much more obvious. Also consider returning and retesting after we have explored the Unity Mixer in Chapter 12, as the Unity Mixer can be configured to mute all other sounds in the game except for Ellen’s Staff. To help compare and contrast, feel free to walk in and out of the alcove to test this as many times as you like.

In this configuration, two Audio Reverb Zone GameObjects have been added to the level, one for outside the alcove in the main game area and one for inside the alcove. I have selected a preset for each that appropriately replicates the acoustic space. There are also two Trigger Areas; one is positioned just inside the alcove, and one is positioned just outside the alcove entering the main game area.

The two Trigger Areas each feature a Box Collider Component with the Is Trigger parameter activated. An InteractOnTrigger script and the GameObjects have been set to the Collider Layer.

Using two Trigger Areas allows for the ability to create a switching system. In this configuration, only one of the Audio Reverb Zone GameObjects will be active at any one time.

The Audio Reverb Zone GameObjects are named Island ReverbZone and Alcove ReverbZone.

Playtest the level again and watch in the Hierarchy as the Audio Reverb Zones GameObjects become Enabled or Disabled, switching from one to the other as the player walks, runs, and jumps back and forth through the entrance to the alcove.

Hierarchy path:

Level01 > Audio > Reverb Zones

Figure 7.1.21 Level01 ReverbZone GameObjects

Select the Trigger Area Alcove in GameObject and view the InteractOnTrigger script Component in the Inspector. You will notice that the On Enter () parameter has both the Alcove ReverbZone and Island ReverbZone GameObjects assigned, and that both are using the GameObject.SetActive function. The Reverb Zone Alcove GameObject is being Enabled and the Reverb Zone Outside GameObject is being Disabled. This means when the player passes through the Box Collider entering the alcove area, the Island ReverbZone GameObject is being turned off and the Alcove ReverbZone GameObject is being activated. This ensures that you are not adding an additional Audio Reverb Zone but, instead, that you are swapping from one to another.

Figure 7.1.22 Trigger Area Alcove in GameObject InteractOnTrigger On Enter () Settings

If you select the Trigger Area Alcove Out GameObject, you will see a similar setup involving an InteractOnTrigger script, again with the Island ReverbZone and Alcove ReverbZone GameObjects assigned to the GameObject.SetActive function. In this case, however, you will notice that the Island ReverbZone GameObject is being Enabled and the Alcove ReverbZone GameObject is being Disabled.

This means when the playable character passes through the Box Collider exiting the alcove area and re-entering the main game level, the Island ReverbZone GameObject is being activated and the Alcove ReverbZone GameObject is being switched off.

Figure 7.1.23 Trigger Area Alcove Out GameObject InteractOnTrigger On Enter () Settings

In a typical game scenario, you have no idea how many times a player may walk back and forth and in and out of an area. To be able to set up a system that can switch back and forth requires the use of two Trigger Areas simultaneously activating and deactivating GameObjects.

It is, however, very important when using two or more Trigger Areas to simultaneously control the same GameObject/s to ensure that these Colliders do not touch one another. If this were to happen, the assigned GameObject/s in question would be rapidly switched on and off when the playable character stands in both Trigger Areas. In the case of using an assigned AudioSource, this can produce a very obvious and audible stuttering effect as the AudioSource is switching very rapidly between being Enabled and Disabled. The best way to check how close your Trigger Areas are to one another is to select the first Trigger Area GameObject in the Hierarchy. Then, hold down the Shift or Ctrl key on PC, Shift or Cmd key on OSX. Finally, left click to select the remaining Trigger Areas in the Hierarchy. This will let you view both Colliders at once in the Scene View. Try this now, using the two Trigger Areas in this example in Level01.

To reiterate, this technique can be used not just for Audio Reverb Zones, but also equally well for ambiences or any other audio that you want to interactively manipulate as the playable character walks back and forth between sections of the level. Consider setting the InteractOnTrigger script to change the volume of ambience AudioSources when entering or exiting sections of the level. Examples where this would be appropriate include, but are not limited to, the alcove area or the small stone room containing one of the final door crystals in the first level. This change in volume would begin to simulate how this sound would naturally reduce in volume when the direct path from the sound source may be partially obscured through walls. You may wish to revisit this technique to expand upon it after learning how to use Unity’s Audio Effects, such as EQs, to reduce the high frequencies when the sound source is obscured from view. This will further enhance these natural acoustic characteristics and produce a more interactive and realistic mix.

Audio Reverb Zones

Reverb is an essential tool to create an immersive audio mix; it provides information instructing the player how far away a sound source is but also helps shape their impression of the space. Just as in real life, you would not expect a bathroom to have the same reverb characteristics as a large canyon. You would expect that both would feature distinctive reverb, but that the individual characteristics of each would be vastly different to replicate the different size and acoustic properties of the space.

Reverb can be applied inside a DAW or from within Unity. This is a creative choice; the advantage to using Unity’s reverb is that all sounds will have cohesion as they are using the same in-game reverb. This reverb setting can then also change dynamically in different areas of the game. For example, you would expect the reverb for footsteps or a gunshot to sound different in areas such as a cavernous cave, an empty bathroom, or a metallic corridor.

However, as discussed in Chapter 2, you could also apply reverb directly to sounds or dialogue within a DAW for creative reasons. One reason for applying the reverb using a DAW, rather than inside Unity, could be that you want to use a totally different reverb to help differentiate or separate specific sounds within the mix. Another could be that you want to have a consistent reverb throughout the game for certain sounds, such as Pause Menu beeps and clicks, and for these not to be affected or changed depending upon the environment the player is in.

You can implement reverb inside Unity using the Audio Reverb Zone Component. You should already be familiar with the majority of the parameter controls for the Audio Reverb Zone, as these are similar to those featured in a typical reverb plugin as used in your DAW of choice. However, like AudioSources, they do have controls for Min Distance and Max Distance with the reverb radiating outwards in a sphere.

You can create and place an Audio Reverb Zone by right clicking in the Hierarchy, selecting Audio and then Audio Reverb Zone. The new Reverb Zone GameObject behaves like any other GameObject. It can be moved, renamed, or structured on the Hierarchy as a Parent or Child GameObject.

Figure 7.2.1 Adding Audio Reverb Zone GameObject

When the Reverb Zone has been placed, you can see that the Min and Max Distance appear as two spheres. In this case, the Wet/Dry control of the reverb would be set 100% when inside the Min Distance. When moving from outside the Min Distance to the edge of the Max Distance, this Wet/Dry knob is effectively being increasingly turned down or reduced, when outside the Max Distance the Wet/Dry parameter is at 0%.

Figure 7.2.2 Audio Reverb Zone Component Visualisation in Scene View

The Reverb Zone Component will automatically have a Transform Component added, as it will be positioned in a location inside the 3D world. There are also a range of parameters available on the Reverb Zone Component that you can use to tailor the reverb to the particular acoustic space you want to emulate. Many of these parameters can also be found on conventional reverb plugins inside a DAW.

Inspector – As with any other GameObject, you can turn the Reverb Zone off and off using the checkbox.

Min Distance – Like conventional AudioSources, the Min Distance represents the area in which all audio will have maximum reverb applied. Outside of the Minimum Distance, the reverb will begin to attenuate. (See Figure 7.2.4.)

Max Distance – Like conventional AudioSources, the Max Distance represents the area in which the reverb will stop attenuating. The reverb level will decrease from the minimum distance to the maximum distance depending upon where the sound source and Listener are located. (See Figure 7.2.3.)

Figure 7.2.3 Audio Reverb Zone Parameters

Reverb Preset – The Reverb Zone Component will allow you to select from a number of presets of acoustic spaces much like any conventional reverb plugin in a DAW.

Room – Controls the size of the room the reverb is simulating.

Room HF – Increase/decrease the Room effect on high frequencies.

Room LF – Increase/decrease the Room effect on low frequencies.

Decay Time – Reverberation RT60 time in seconds.

Decay HFRatio – High-frequency to low-frequency decay time ratio.

Reflections – Early reflections level relative to room effect.

Reflections Delay – Early reflections delay time relative to room effect.

Reverb – Late reverberation level relative to room effect.

Reverb Delay – Late reverberation delay time relative to first reflection in seconds.

HF Reference – Sets the reference for high frequency in Hz used for Decay and Room parameters.

LF Reference – Sets the reference for low frequency in Hz used for Decay and Room parameters.

Diffusion – Reverberation diffusion (echo density) in percent.

Density – Reverberation density (modal density) in percent.

Figure 7.2.4 Unity Audio Reverb Zone Min Max Reverb over Distance

You will find that you are unable to further tweak the Reverb Preset settings. One workaround you can use is to place the Reverb Zone in the level, begin playing the game, then select a preset that most closely resembles the acoustic environment you want. Finally, then change the Reverb Preset to User.

This will keep the various parameters in their original settings but unlock the individual controls, allowing you to further tweak any of the parameters. Adjust these while the game is running until you’re happy with each parameter.

Finally, to save the Reverb Zone settings, copy the Reverb Zone Component settings while Unity is still in Play Mode. Exit out of Play Mode and paste your copied Component values back on the Reverb Zone Component when back in Edit Mode. This final step is important as Unity will not save any of the changes that are made while the game is running.

Figure 7.2.5 Audio Reverb Zone Presets and User Setting

Setting Reverb Zone parameters

A common issue many Sound Designers have when learning how to mix is that they can hear the reverb parameters are changing the acoustic environment, but they don’t know if these changes are better or worse. It can be very difficult to hear how each parameter of the reverb is affecting the whole mix when listening to all the varied elements such as Foley, dialogue, main SFX, and ambience playing at once.

The following technique will allow you to much more clearly and easily hear how each parameter is affecting the reverb.

Begin by revisiting and opening the Level01 Scene of the With Audio project.

Add in an AudioSource GameObject, set this to Play On Awake, then to Loop, and to playback using 2D spatialisation. I have added a number of Audio Assets that have been specifically created to let you more easily hear the individual Audio Reverb Zone characteristics.

These are located in the following folder within the Project Panel Assets:

Assets > 3DGameKit > Audio > Misc > Reverb Zone Test SFX

Preview these sounds to have a listen to them; see if you notice any similarities. They are all short sounds with very defined attack transients such as claps, clicks, and a snare drum. They also do not have prominent reverb included within the sound recordings.

These sounds have been chosen for a purpose. Listening to short, sharp, transient sounds through a reverb will allow you to hear much more clearly the actual characteristics of the reverb, as the audio files are very short in length.

Pick one of these Audio Assets from the folder and add it to the AudioSource you have just created

Play the level and listen to the characteristics of the Reverb Zone Outside GameObject

Now walk into the alcove, activating the Reverb Zone Alcove GameObject and compare and contrast the two reverb characteristics

Are you able to hear these in much more detail than before?

If so, great; this specific technique is just as effective when listening or comparing reverb presets, not only inside Unity, but also just as well for Music Production or audio post-production.

So, hopefully you can hear the differences in the Reverb characteristics, but you may still struggle with working out how to set the specific parameters to their optimal settings.

When designing reverb characteristics, I use this specific method to help me make better creative choices as efficiently as possible.

Use the existing AudioSource you just created with one of the example Audio Assets from the Reverb Zone Test SFX Project Panel folder. Begin quickly trying the various Reverb Presets and listening to the reverb characteristics. It can help to pick a Reverb Zone Preset if you move the Scene View camera to look at the area of the level the Audio Reverb Zone is being set for. Try not to listen to a single preset for more than 10 seconds; this is because the human ear very quickly adjusts to what it is listening to, and this can influence you to make bad creative decisions. Listen to various Reverb Presets and try to quickly pick the one you think is ‘close enough’.

Next, adjust each parameter, setting this to the lowest value, a middle value, and the top value. Decide if the parameter sounds best in the low, mid, or high setting before adjusting the parameter to this setting and moving onto the next parameter. Again, try to make these decisions very quickly to avoid your ear becoming used to the sound and making it harder to make critical decisions.

Figure 7.2.6 Audio Reverb Zone Example Low, Mid, and High Parameter Values

When you have set all the parameters to the optimal low, middle, or high setting, then begin fine tuning the exact range that sounds best by picking a smaller range of the parameter and again trying low, middle, and high. At this point, you should attempt to over-exaggerate the reverb characteristics that fit the acoustic space you are attempting to emulate.

Figure 7.2.7 Audio Reverb Zone ‘Mid’: Low, Mid, and High Parameter Values

Continue refining each parameter by quickly listening to low, mid, and high in increasingly smaller adjustments until you can no longer hear any difference between the three. Having exaggerated the characteristics, you should find that when putting complex source material featuring sounds across the whole mix, these characteristics will still be present but not as obvious compared with only listening to the single, short, transient sound.

Copy the Audio Reverb Zone Component values, stop Unity playing, and paste the Component values when you are back in Edit Mode. Now, take a 5-minute break away from the computer, preferably in a different room. When returning, have one final listen to the Audio Reverb Zone when Unity is in Play Mode to see how much the reverb characteristics reflect the acoustic environment they are emulating. If you are happy, then move onto the next Audio Reverb Zone and repeat the previous process. With enough experience, you will soon be able to pick a preset and know which parameters to adjust and predict with high accuracy, where to set the parameter values to achieve exactly the effect you want. Using this method is effectively training your ear to accomplish this.

Fitting a round peg in a square (or irregularly shaped) hole

You may notice if you observe the Audio Reverb Zones used within the Level01 Scene in the With Audio project that I have set the Min and Max Distance parameters to the same value. You may also have noticed that these Reverb Zones are much larger than the area of the game they are intended to be used within.

These choices were not made by accident; there is a very specific purpose for choosing these Min and Max Distance settings. As you are now aware, the AudioSource and Audio Reverb Zone Components are spherical in shape, and the majority of areas within a game are not. Case in point is the alcove area explored earlier; this is more or less triangular in shape.

The main issue you will inevitably come across is how to make sure that all spaces within a room have appropriate Min and Max Distance parameters for the 3D AudioSources or the Audio Reverb Zones.

Using a spherical shape, it seems impossible to make sure that all corners of a square room will have equal coverage without the Audio Reverb Zone or AudioSource overlapping into adjoining areas or rooms.

Figure 7.3.1 Diagram Showing Spherical AudioSource Min Max Distance in Square Shaped Room

If you set up a pair of Trigger Areas, much like in the example covered within this chapter, you can adjust the Min and Max Distance parameters to be much larger than the area required, ensuring these sound optimal for that specific space. Then use the Trigger Areas to switch these GameObjects on and off when entering or exiting the room. This stops your Audio Reverb Zones or AudioSources from overlapping with nearby areas and ensures the player is only able to hear these when they are required.

5 quick tips

You can place multiple Reverb Zones in the same location and use a combination of different parameters to further shape the acoustic space.

Make sure you test your Trigger Areas to ensure the player cannot sneak past them without activating them, or that they aren’t so large they can be inadvertently triggered. Try to purposely cause these issues when playtesting the game and re-adjust the Trigger Areas if required.

Not all AudioSources should have the Reverb Zone Mix set to a value of 1. To create depth within your mix, consider setting the Reverb Zone Mix parameter on the AudioSource to different values for the various elements of the mix. Dialogue typically benefits from less reverb to increase the intelligibility of the speech, whereas footsteps benefit from more reverb to give a greater sense of the space.

If you cannot see the Collider shapes in the Scene View, make sure the Gizmos button in the Scene Panel is activated.

Remember to copy over and import the additional reverb SFX Assets from the With Audio Example project into your own Silent project.

Chapter 7 practical tasks

The practical task is to follow the instructions provided in this chapter for placing a Trigger Area in Level01 and set this to change Reverb Zones. After mastering these skills, think about where you would like to begin placing your Audio Reverb Zones within the levels for different reverb characteristics, such as the stone room in Level01 containing a crystal. Create Trigger Areas in various locations to Enable and Disable your Ambience and Reverb Zones with the aim of creating a dynamic and interactive audio soundscape.

Replicate the Trigger Area example to play a sound in front of the boss door

Consider where else within the level you may want to trigger an additional sound to play

Consider any sections where you may wish to change a parameter for a looping AudioSource such as volume or pitch when the player reaches a particular point in the level

Set up Reverb Zones and have Trigger Areas to switch between them, as shown in the example

Please also consider switching AudioSources on and off in certain areas to make a more immersive and reactive ambience. Consider making a note to revisit this section when you have learned how to apply additional effects to an AudioSource, such as EQ, and think where you may want to change these parameters when Ellen is in a certain place in the level or crosses a particular boundary to increase the immersion and dynamic capabilities of the mix even further.

8 Recording, processing, and implementing dialogue

DOI: 10.4324/9781003055167-8

Dialogue is an essential tool for helping deliver a narrative experience in video games. Almost all big budget AAA games and a large majority of indie video games will feature interactive voice-overs of some description.

This chapter will focus on dialogue pre-production, recording, processing, and implementation, specifically in relation to Game Audio and localisation. It will look at how the existing subtitle system has been set up in the 3D GameKit and how you can modify this to say whatever you want, wherever you want.

Pre-production

Dialogue is a very important part of Game Audio; it can drive the narrative portion of the gameplay, often providing not only the story and instructions but also context to the player’s actions. It can emanate as if from the playable character, be delivered by a NPC accompanying the player, and be placed in the gameworld or from an unseen source, such as through a walkie talkie or communications device.

The dialogue in games is written by the Narrative Designer. Quite often this is the person/people that come up with the story, how it develops, the characters, and the lines of dialogue they speak. The Sound Designer is responsible for recording, implementing, and mixing the dialogue within the game.

The Narrative Designer will write a script, which is then given to the voice actors and the Sound Designer. This script differs from a traditional movie script as it will often contain additional information and is usually laid out in a Google or Microsoft Excel Spreadsheet.

The script will often be colour coded and list:

The name of the character speaking

A unique file identification name

The location and/or event in the game that has triggered the line of dialogue

The lines of dialogue to be spoken

Directions for the voice actor when performing the line

A checkbox to say if the line has been recorded

A checkbox to say if the line needs audio processing

A checkbox to say the line has now been implemented in the game

A space for additional comments

An example Google Sheet and Microsoft Excel Spreadsheet has been created and partially filled in with the information relating to the existing subtitle system in the 3D GameKit. You can download and edit this yourself as either a Google Doc or Microsoft Excel file from the Chapter 8 DLC. Fill this out when completing your project and go ahead and modify it if you want to change the existing subtitle system used within the project.

At this pre-production stage of the dialogue process, the Sound Designer will plan out how they want to record the lines and what equipment to use. Although getting actors into a recording studio to perform dialogue lines may seem very similar to audio post-production for a movie, video games have individual circumstances that must also be considered.

Actors in a movie will generally be able to watch back the film scene they performed live, using the original audio recorded on set as a guide while they are performing their takes. This helps them to get into character when performing Automated Dialogue Replacement (ADR). With games, this is not always possible. Quite often there is not any original dialogue because the performance would not have first been filmed on location, but may be created by an Animator at a later date to match the recorded dialogue.

When you approach dialogue recording, the first thing you should consider is, if two or more people are having a conversation, will the lines be recorded with the actors separately or together in the same room?

There are advantages and disadvantages to both methods. One advantage to recording the actors together is that you will get a more natural performance as people instinctively wait an appropriate amount of time between words and sentences when having a conversation and may change or modulate their performance depending upon the other actor’s delivery of the dialogue. This can help the actors to perform better and the end result can seem much more fluid than recording the actors in isolation. Recording using this method allows the actors to feed off each other and deliver a better performance, but it does have downsides that make it potentially unsuitable for some games.

A game that made the choice early in pre-production to record dialogue from the main two actors together was FIREWATCH (2016). If you are not familiar the dialogue/story in FIREWATCH – minor spoiler alert, the game centres around a man and a woman who never meet in person but communicate solely through walkie talkies.

The Audio Lead/Narrative Designer Chris Remo decided that the method he wanted to use to get the best performance was to not allow the actors to meet to discuss the roles or their performance before the recording sessions, and to record both actors performing together but physically isolated from one another. This recording technique mirrored how the characters in the game would communicate and was designed to replicate as closely as possible how naturally the relationship between the characters would develop as they became more familiar with each other throughout the story. This was incredibly successful as the actors initially sounded somewhat nervous and unfamiliar with each other, then later in the story as they had become much more friendly and comfortable with one another, the performance naturally reflected this.

One disadvantage to this method is that it is more expensive to pay multiple actors an hourly rate, as they are not able to perform as many lines in an hour timeframe when compared with recording them separately (and especially in FIREWATCH’s case paying for two recording studios simultaneously).

Another disadvantage is that it is natural in conversations for people to interrupt each other slightly, and this becomes much more pronounced if the actors are performing a highly emotional conversation such as an argument. Recording both actors using this method can cause issues when attempting to implement the audio. As games generally trigger one line to its completion, then the next line and so forth, if actors are speaking over one another, this becomes very difficult to do. This is especially true if they are in the same room, as their voices would bleed into each other’s microphones, or ‘mics’. If you wish to record two actors simultaneously, it is important to ensure you have total separation in the mics.

Recording dialogue

When recording the dialogue, I would recommend having the voice actors perform in a fairly acoustically dead sounding room to minimise reverb. I also recommend using a compressor; the compressor should be set so that the voice actor’s lines are constrained to within about 12–15 dB of dynamic range per line. One reason for using fairly heavy compression on the dialogue is that if there is too much dynamic range between individual words or lines, it can be very difficult to mix the dialogue line if the dynamic range is too great as some parts of the sentence will be too loud, and other parts too quiet.

Another reason for employing this method is that you will sometimes implement dialogue that can be triggered at any point in the game by a player’s actions, as you may not be able to predict with 100% accuracy what other sound sources are active in the scene, or how loud these may be. Ensuring you appropriately limit the dynamic range of the speech means you can set the volume and know it will play back at a more consistent volume throughout the dialogue line. Manually adjusting each line of dialogue in the DAW or a Wave Editor will of course correct this issue, but will require more time to be spent rather than simply just using a compressor in the first place.

A final point to consider is setting the gain so that you are recording the dialogue at a high level. As the dialogue will all be normalised to −1 dB, like with the SFX, it is imperative that you maintain a good signal to noise ratio. Using compression when recording can also help ensure that you are able to record at a high level without risking clipping/overloading the recording input gain if the voice actor decided to perform at a much louder volume than you were anticipating.

You should also consider which type of mic to use to record the dialogue. Typically, this choice is dictated by the actor’s voice; you want to use the mic that will best complement it. You can also consider if you want to record dialogue very naturally using the full frequency range. In this scenario, it is common to use a mic such as an AKG 414 or Neumann U87. If you want to emulate the dialogue sound used in films, then you would usually record the voice actor using a fixed boom mic such as Sennheiser MKH 60 or Lavaliere mic, as these are the mics most often used in film/TV audio post-production.

There is no right or wrong choice for mics or mic placement. Much like recording any instrument, the decision is generally decided according to how you want the final outcome to sound. However, the following techniques are considered standard practice for recording voice-overs close up using a condenser or slightly farther away using a shotgun mic.

Condenser close-up

Begin by placing a condenser mic on a stand and position this so the capsule is approximately in line with the voice actor’s mouth. Next, if you have a pop shield, then attach this to the mic stand and position this between 2 and 6 inches away from the mic capsule so it will be in between the performer and the mic. The pop shield is a thin piece of material that is designed to reduce the plosive ‘P–Puh’ and ‘B–Buh’ voice sounds. Have the voice actor stand in front of the microphone and perform a few lines as they will when recording. Move the microphone and pop shield around to the optimal position.

Figure 8.2.1 Dialogue Recording Technique Using Condenser Microphone Close to Mouth

Shotgun mic technique

Have the voice actor or ‘talent’ face directly forwards towards the mic. Ask them to make a fist with either of their arms, hold the arm out directly in front of them, and then raise this same arm upwards at a 45-degree angle. Place a sensitive condenser mic where the voice actor’s fist is and angle this to point downwards towards the voice actor’s chin.

Figure 8.2.2 Dialogue Recording Technique Using Shotgun Microphone

Changing the angle of the mic slightly to point upwards towards the voice actor’s forehead will result in a more nasally characteristic; angling the mic towards their chest will result in a bassier/more chesty characteristic. These adjustments will allow you to exaggerate or reduce a naturalistic recording for a voice actor of any height. It is often worth quickly experimenting with mic choice or placement by having the voice actor read through a few lines as a warm-up before making your final selection.

Tips for getting an authentic performance

If the actor is able to perform the motions needed for the line, it will sound more natural, such as if they are crouched over, out of breath etc. Have them physically take the position (but remember to move the mic accordingly). If the line should be delivered as if under strain or effort, consider asking the voice-over actor to hold a heavy object to help get into character while recording the take.

I have often found when recording voice actors with limited experience, if you detect that they are subtly modifying their performance over time, that it is a good idea to regularly play a reference recording of themselves from earlier in the recording session back to them. This becomes especially important if the voice actor is performing in an accent or using a voice that is in any way different from their own natural speaking voice. Quite often, an inexperienced voice actor will slowly unintentionally start modifying their accent or voice as the recording session progresses. This can result in a gradual performance modification that is not noticeable when recording or listening sequentially line to line but is very noticeable when listening back from earlier in the recording session compared with later, more recent lines.

Another approach I try to take when recording dialogue is, if I know I will heavily process the voice, I will spend some time with the voice actor setting up placeholder/temporary plugin effects on an Auxiliary track and routing their audio inside the DAW to monitor the recording with the effects applied. This can help the voice actor immensely as it allows them to get into character and they can tailor their performance to how it will sound with the effects applied. By adding in the effect using an Auxiliary track, I am still able to record the voice actor without committing to or printing the effects into the recording. This allows me to fine tune the processing later.

Processing dialogue

Processing dialogue is quite a common technique; it is basically a variation of setting up an Auxiliary reverb track when recording vocals to help the singer feel more confident when delivering their performance. It has been used on a number of feature films, such as Star Wars: The Force Awakens (2015). The dialogue sound when Adam Driver (playing Kylo Ren) is wearing his mask was created using a number of pieces of outboard audio equipment. His dialogue was then recorded by using a wireless microphone hidden inside the mask and with these effects already applied. It helped him to get into character more easily and provide a more realistic performance as he was able to modulate his performance live alongside the effects, rather than the processing being applied later in post-production.

However, recording directly through a number of creative outboard effects processors is not always entirely suitable for application in games. As has been covered briefly before, you will have the full script separated into individual audio files; every language should have an identical folder of files. If you intend on using a substantial amount of outboard processing, every dialogue file from each language will have to be re-recorded through the outboard processors in real time, exported, and then named correctly. This is obviously a very time-consuming process with a considerable risk that a file will be named incorrectly and not play in that language. One advantage of using plugins is that you can save out a selection of presets which can then easily be applied to batch convert a number of files using a Wave Editor such as Audacity, as covered in Chapter 3.

It is also common in games to use software such as Izotope RX8 to provide essential, but less creative forms of audio processing. This is to ensure all dialogue files have any additional noise removed or minimised as much as possible, such as pops, clicks, clothing rustles, or noisy equipment.

Implementing dialogue

As games are interactive by definition, you will have to modify your workflow to ensure consistency within the limitations of the game engine. This interactivity can offer benefits that are not possible in conventional linear media.

In games, you are able to offer the player a choice of dialogue options, allowing them to dictate how a conversation plays out and possibly even the ending of the game.

Many games offer this functionality. A few examples include:

Detroit Become Human (2018)

Heavy Rain (2010)

LA Noire (2011)

Beyond Two Souls (2013)

Until Dawn (2015)

Fallout game series

Elder Scrolls game series

Telltale game series

Mass Effect game series

Unlike film, it is important to correctly set up a priority system for the dialogue. You may have the main characters speaking – this is usually most important – and then lots of NPCs semi-randomly speaking to make the gameworld feel a lot more alive and interactive. Games such as Middle-Earth: Shadow of Mordor (2014) or Red Dead Redemption 2 (2018) rely very heavily on background dialogue to immerse the player in the gameworld.

A priority system is important because dialogue files are usually streamed to save on Random Access Memory (RAM), so you are only able to load or play a certain number of dialogue lines simultaneously. As the player is in control to a large extent of the pace of the story, an important event could potentially happen at any time. If a background NPC is having a conversation and something dramatic happens, you do not want to have to wait until the background line has finished playing before hearing the main character’s reaction dialogue. A noticeable example of this would be crashing a car in Grand Theft Auto 5 (2013). This event will stop the sidekick NPC from talking about the upcoming task or mission and cause the NPC to then comment on the player’s driving skills, before then resuming talking to the player about the mission.

A priority system for dialogue files would be able to interrupt and stop any extra or erroneous dialogue that is playing and begin playing more important dialogue from the main character automatically. You have already explored the priority system in Unity for SFX. A dialogue priority system would use a separate, much more complex dialogue-specific system rather than the Priority parameter on the AudioSource. To allow for this level of functionality, you would have to code in your own fairly complex and comprehensive dialogue system. This would enable you to implement a feature to naturally Fade Out the erroneous dialogue and begin playing the important dialogue.

As only certain games will actually require such a complex dialogue priority system, and as it would not be beneficial for any of the projects in this book, this topic will not be explored in further detail. There is, however, additional information available on the internet from interviews with the developers on how various Open-World games, such as Grand Theft Auto 5 (2013), have implemented such a system.

Localisation

Recording dialogue for video games has additional considerations that must be taken into account. Games are often released with the dialogue recorded in different languages, giving them greater international appeal. This is called localisation.

When considering how subtitles are often implemented in games, if you take the example of recording two actors having a conversation together, although you could export the entire conversation as a single audio file, this implementation will not work best for an automated code-based subtitle system. Subtitles are often implemented into games to display the text while the dialogue line is currently playing. This means the correct subtitles should appear and disappear off the screen when the line in question is being played. If an entire 20-line conversation is exported as a single audio file, the game engine will not know which character is speaking or where one line of dialogue ends and another begins. Therefore, the code-based subtitle system will not be able to display the relevant subtitle for each line of dialogue while it is currently being played. If each line of dialogue was exported and implemented as individual audio files, an automated code-based subtitle system would then be able to display the associated subtitle, including the speaking character name, while the line in question is playing back inside the game.

Using the method of triggering the entire conversation as either a single audio file or one audio file per character, a game developer will be required to manually add in cues to the audio file to trigger the subtitles. Again, as you will inevitably run into the issue of differing lengths of the audio files across various languages, using an automated code-based subtitle system that will display the text on screen while the line is currently playing will be quicker. This system also requires less manual work and is generally more accurate across the various languages.

Games are generally able to support multiple languages. One of the Sound Designer’s responsibilities is to make sure that each supported language for the game has a set of identically named dialogue files in a separate assets folder per language.

These are often prefaced with a three-letter code to signify which language is which.

A few examples include:

ENG – English

FRA – French

SPA – Spanish

ITA – Italian

GER – German

BRA – Brazilian Portuguese

SWE – Swedish

RUS – Russian

The five most popular languages are English, French, Italian, German, and Spanish. These are collectively known in the industry as EFIGS.

When a game is started, the programmers will write a piece of code that will detect which language the consumer’s console/PC is set to and ensure that the audio files for that language are loaded automatically. This means that if each language uses the same file names, the dialogue will only have to be implemented once for all languages and the existing code can trigger the associated dialogue and subtitle file for the selected language.

Dialogue implementation in 3D GameKit

The 3D GameKit does have code support within it for localisation; however, the project has only been set up for the English language. When playing through the levels, there are UI Text subtitles that will pop up throughout the level, giving hints to the person playing the game as to their objectives or the controls. The first example of this can be seen immediately after starting the Level01 Scene file.

Figure 8.6.1 First Subtitle at Start of Level01

Current subtitle implementation in Level01

The hint text exists as part of the Level01InformationZones GameObject.

The DialogueCanvas GameObject is used to display the subtitle text on screen.

The Localizer GameObject contains a list of all of the subtitle lines used in this level.

The LVL01_InfoZone01 to LVL01_InfoZone05 GameObjects contain the Trigger Areas to Enable/Disable the various subtitle texts as the player progresses through the level.

Figure 8.6.2 InfoZone GameObjects in Hierarchy

LVL01_InfoZone02 GameObject is used for the hint, ‘Can I jump over this if I press SPACE?’ that will appear near the start of Level01 Scene, when the player is expected to jump across from the starting area into the main section of the map.

Figure 8.6.3 Level01_InfoZone02 GameObject in Hierarchy, Scene View, and Inspector

It consists of a single GameObject containing a Sphere Collider Component and an InteractOnTrigger script.

The Script will check if the playable character has walked inside of the Sphere Collider. If they have, it will perform the functions added to the On Enter () event.

In this particular case, the DialogueCanvas GameObject has been added as a variable, and LV0L_01INFO2 has been entered into the Text Box.

If you click on the Localizer GameObject, you will see a script called Translator in the Inspector.

Figure 8.6.4 Localizer GameObject and Translator Script

You can see in the Translator script that it has been set to the English language. It also contains a list with a name identifier LVL01_INFO1, LVL01_INFO2 etc. and then the text that is displayed for each identifier immediately to the right, such as ‘Can I jump over this if I press SPACE?’

You will notice that you are unable to edit this text from the Inspector.

Click the dropdown button on Phrases then click on the Level01EnglishInformationPoints. The GameObject that has been placed in the variable will be highlighted in the Project Panel.

Figure 8.6.5 EnglishInformationPoints Asset Location in Project Panel

Project Panel Path:

Assets > 3D GameKit > Localisation

Click on the Level01EnglishInformationPoints Asset in the Project Panel, and then look at the Asset information in the Inspector Panel.

Figure 8.6.6 EnglishInformationPoints Asset Selected in the Project Panel and Editable in the Inspector Panel

You can now edit the number of Phrases using the value in the Size Variable, such as the name of the phrase and Text content that will be displayed in game. Any changes made here will be reflected in the Translator script when viewed on the Localizer GameObject.

Implementing dialogue along with subtitles

You can now add in audio dialogue to accompany the subtitles.

Select the LVL01_InfoZone02 GameObject in the Hierarchy and create an AudioSource to use for dialogue playback and name this. DO NOT set the AudioSource to Play On Awake, as this will be triggered to play using other means explained in later instructions. Also set the Spatial Blend parameter to play back in 2D, and add the dialogue line Audio Asset you created to the AudioClip parameter.

Figure 8.6.7 Adding AudioSource GameObject for Dialogue Playback in LVL01_InfoZone02 GameObject

Return to the LVL01_InfoZone02 GameObject and click the plus (+) button in the bottom right-hand corner of the On Enter () event section of the Inspector as shown in the next image (1).

Left click and hold to drag and drop the dialogue AudioSource you have just created into the new variable that reads None (Object).

Left click on the button that currently reads No Function and select the AudioSource > Play () function.

Figure 8.6.8 Assigning Dialogue AudioSource to InteractOnTrigger Script

This will now play the dialogue line in the AudioSource when you enter the Trigger Area. If you playtest the game, you may also notice that if the player quickly enters and then leaves the Trigger Area, the dialogue will continue to play despite the subtitles no longer being displayed on screen.

You can make one more adjustment to ensure that when you leave the Trigger Area, the audio will stop playing along with the subtitles disappearing.

Click the plus (+) button in the bottom right-hand corner of the On Exit () Event section of the Inspector to add in a new variable, as indicated by the number (2) in the previous image.

Drag and drop the same dialogue AudioSource you have just created into the new variable that reads None (Object).

Click on the button that currently reads No Function and select the AudioSource > Stop () function.

Figure 8.6.9 Setting AudioSource.Play and AudioSource.Stop Functions in InteractOnTrigger Script

Press the Unity Play button and begin playing the level. You will hear the dialogue line begin to play when entering the Trigger Area. You will hear that the dialogue line will only play to completion while the Ellen playable character remains inside the Sphere Collider; it will stop playing if the Ellen playable character leaves the Collider area before the line has finished playing.

It is very important to thoroughly test your work to ensure that it behaves appropriately in relation to any actions the player may reasonably take. In this case, you are testing to make sure the dialogue will play to completion if the player plays the game quite slowly. You also then need to check how the game will behave if the player were to be speed-running through the level as quickly as possible. In this scenario, it is possible that they could be entering the next Trigger Area/Collider while the previous Trigger Area/Collider dialogue line is still playing. This would cause the player to hear overlapping dialogue that would sound quite unnatural and messy. If you follow these steps correctly, you will stop the dialogue line AudioSource playing when leaving the Collider. Therefore, only one dialogue line will play at a time, and if necessary, the game will stop the current dialogue line from playing if the player is moving through the level very quickly.

You can follow these steps to create an AudioSource and dialogue AudioClip Asset to accompany each of the InfoZone GameObject lines of dialogue in Level01.

Current subtitle implementation in Level02

Level02 currently features one subtitle when immediately starting the level. This can be found within the Level02InformationZones GameObject. This uses the same subtitle setup as described in the previous section. You can add in an AudioSource GameObject and set this to Start and Stop playing by assigning the AudioSource GameObject to the On Enter and On Exit parameters of the InteractOnTrigger script Component as described in previous steps.

You can see this implementation and some placeholder dialogue files have been added into the With Audio version of the 3D GameKit Project available in the DLC resources folder.

Moving or adding additional InfoZone Trigger Areas

You can, if you want, change the existing text displayed on screen by modifying the Level01EnglishInformationPoints and Level02EnglishInformationPoints Assets in the Project Panel. You could then select the existing InfoZone GameObjects containing the Sphere Collider to reposition and move these wherever you want in the game levels. If you want, you can also change the Radius parameter of the Sphere Collider to increase or decrease the size of the Sphere Collider.

Warning

When moving or placing additional subtitle/dialogue Trigger Areas, it is very important that the Sphere Colliders do not touch one another.

Like the Trigger Area example in Chapter 6, if the playable character is able to stand in two subtitle/dialogue Trigger Area Colliders at the same time, this will likely result in two dialogue lines displaying and playing over the top of one another.

It is possible to create additional Trigger Areas if you want to add in additional dialogue subtitles and speech. The easiest way to accomplish this is to select one of the existing InfoZone GameObjects in the Hierarchy and duplicate it. In the next example, I am duplicating the LVL02_InfoZone01 GameObject in the Level02 Scene Hierarchy.

Select the LVL02_InfoZone01 GameObject in the Hierarchy and press Ctrl + D on PC or Cmd + D on OSX

Rename this new GameObject to LVL02_InfoZone02

Move and reposition the LVL02_InfoZone02 GameObject where you require it in the Scene

Next, select the EnglishInformationPoints Asset associated with the specific level; in this case, I will select the Level02EnglishInformationPoints Asset in the Project Panel

Adjust the Size parameter from 1 to 2

Rename the new variable from LVL02_INFO1 to LVL02_INFO2

Type in the subtitle text you want to display in the text box immediately to the right of LVL02_INFO2; in the next example, I have written ‘Example dialogue’

The Level02EnglishInformationPoints Asset should now look like the following in the Inspector Panel.

Figure 8.6.10 Level02 EnglishInformationPoints Asset with Additional Phrase Added

Now return to the Hierarchy and select the LVL02_InfoZone02 GameObject

Change the text variables on the On Enter event parameter from LVL02_INFO1 to LVL02_INFO2

If you have already added in implementation to play an AudioSource, then update the dialogue AudioClip on the associated AudioSource for the new subtitle dialogue line

Playtest the game to check that your new subtitle line is appearing on screen when you require

5 quick tips

When planning/budgeting for a recording session with a voice actor, you will need to factor in several short breaks to allow them to rest their voice. The breaks may need to be longer and more frequent, especially if you are asking them to strain their voice, for example when shouting in anger.

When recording a voice actor, it is considered good practice to provide them with a bottle of water.

If you can hear a voice actor’s lip sounds when using a sensitive condenser mic, asking them to remove lipstick (if they are wearing any) or to eat an apple can help reduce this effect.

I normally ask voice actors to remove all jangly jewellery, watches, or anything else on them that may cause additional noise.

It may be helpful to record all the dialogue NOT in sequential order. I often start with something short and easy and leave anything such as shouting until nearer the end of the session to help preserve the voice actor’s vocal cords.

Additional Tip

It can be quite nerve racking for a voice actor or singer when standing in the recording booth alone. If possible, leave the talk back mic on when not recording so they are involved in any conversations happening in the control room.

Chapter 8 practical tasks

In Game Development, you cannot always wait until the entire game has been completed to begin implementing audio (unlike the fully finished 3D GameKit Project provided). It is very common across all departments to use temporary audio, videos, or art until the final version has been completed. Doing this will allow you to quickly swap in the finished Asset at a later date and continue working in the meantime.

Task 1

If you do not have access to a mic or voice actor, consider improvising by recording using your phone or alternatively using a ‘text to speech’ system such as Amazon Polly to create and process AudioClips for each of the subtitle lines present in the game. These audio files can always be replaced at a later date with final dialogue files should you be able to find a performer or the equipment required. You may also find it helpful to write the content of the lines ahead of time in a list or spreadsheet before beginning to record; this will save you time as you won’t have to keep switching back and forth between your DAW and Unity.

Task 2

You should then implement this dialogue in Unity to work alongside the existing subtitle system in the 3D GameKit.

Task 3 (optional)

You are free to modify the existing dialogue setup in-game if you want to implement your own narrative or story. The easiest way to do this is to move the existing dialogue GameObjects/Triggers. If you want to add more dialogue lines, then duplicate some of the existing GameObjects before altering the Level01EnglishInformationPoints and Level02EnglishInformationPoints Asset found within the Project Panel.

Try to execute your new dialogue in a creative, technical way that supports the gameplay experience for the player.

9 Audio Implementation of character and enemy SFX

DOI: 10.4324/9781003055167-9

This chapter will cover the implementation and setup of a number of mechanics in the 3D GameKit, such as the playable characters footsteps, weapons, and enemy SFX as well as a core audio component created specifically for the 3D GameKit Project called the RandomAudioPlayer.

You should create and then implement your own audio by following the instructions in this chapter.

For each mechanic, it will be outlined if you need to create a Seamless Looping Audio Asset or a set of One Shot Audio Asset variations. The general rule to follow is that if the AudioSource is using the Loop parameter, then a Seamless Looping Audio Asset is required. If the Loop parameter is not activated, then this requires a singular One Shot Audio Asset.

How to trigger audio on:

Ellen Playable Character

Chomper Enemy

Spitter Enemy

Grenadier Enemy

You will explore how each of these SFX has been implemented in the 3D GameKit. In Chapter 13, you will revisit some of these mechanics and explore how you could improve upon this initial Audio Implementation.

RandomAudioPlayer script

Chapter 3 spoke about the importance of variation when triggering repetitive SFX such as footsteps. The goal of a Game Audio Sound Designer is to increase and maintain the immersion of the player. One of the easiest ways to break this immersion is when a player becomes aware that they are hearing the same SFX repeated multiple times. For example, using only one footstep sound in a game will quickly become repetitive and either attract the player’s attention to the audio in a negative way, or cause them to subconsciously start ignoring the audio. Both of these outcomes will ultimately detract from their enjoyment and immersion in the game.

You can decrease the players listening fatigue using several techniques:

Applying random volume variation

Applying random pitch variation

Having Unity randomly select and play from a number of Audio Assets using a Sound Bank or Array

The RandomAudioPlayer (Script) Component can be used in many different scenarios across the majority of game mechanics. It is used in conjunction with an AudioSource Component and will modify the AudioSource parameters by choosing random values within the range you set. This happens automatically every time the AudioSource is triggered to play, drastically reducing fatigue caused by repetition.

Figure 9.1.1 Random Audio Player Script Component

Min and Max Volume

The Min Volume and Max Volume Variables will overwrite the current setting in the AudioSource for volume whenever the sound is triggered. Unity will randomly pick a value between the minimum and maximum volume range and then apply this to the Volume parameter of the AudioSource; this in effect is giving you control over the dynamics of each sound. The random value selected will never be smaller or ‘quieter’ than the value entered in the Min Volume Variable, and likewise the random value selected will never be bigger or ‘louder’ than the value entered into the Max Volume Variable. This means you cannot enter a Max Volume value of 2 because the Volume parameter on the AudioSource only goes between a range 0 and 1. The RandomAudioPlayer has been coded specifically to allow a maximum value of 1. If you try to enter a value greater than 1, you will notice that the script will adjust the incorrect value to 1 for the Max Volume. Similarly, if you tried to enter a Min Volume value lower than 0, the script will adjust the incorrect value to 0.

If you do not want to apply any random volume to an AudioSource, you can enter the same value in the Min Volume and Max Volume parameters. This may be particularly useful for a looping sound if you do not want the sound to change volume or pitch when looping from the end of the audio file back to the beginning.

The idea of using a minimum and maximum value instead of a single static value to control a parameter is something that is unique to video game mixing. In a DAW, you will have a volume fader, similar to the AudioSource volume parameter. However, not all game engines will contain a Component that will be able to perform the additional functions included within the RandomAudioPlayer script automatically.

When mixing music or film/TV audio, you can use a number of tools such as clip gain automation to mix each piece of audio to make a volume value correspond with a specific point in the timeline. This method mixing is very well suited for linear media; however, it is not that appropriate for non-linear interactive games. When actually performing a musical instrument or actions such as Foley with multiple variations, the performer will naturally play or perform with dynamics, as in the volume of each individual note or action will be slightly louder or quieter or have subtle differences within the performance than the next. Using a volume range with min and max values is a way of simulating the natural dynamics of human interaction. Without this natural dynamic or volume fluctuation of the audio, the game would sound somewhat robotic as every sound variation for your sounds would play back in exactly the same way when using a static volume control.

The best method I have found when thinking about mixing using a min and max value for your volume is to begin thinking about how loud or quiet on average this AudioSource should play back in the game. By this I mean, is the sound you are mixing supposed to be a subtle background element that should be quiet, or is it a loud, prominent sound that should clearly be audible in the mix?

Begin by deciding upon an estimated value for your average volume, and then decide how much variation you would like to include for this sound.

The bigger the difference between the minimum and maximum, the larger and more obvious your volume variation will be. The smaller the difference between the minimum and maximum, the more subtle or smaller the volume difference will be between the values selected for your minimum and maximum.

For example, if you wanted the average volume of the sound to be around 0.5, you should ensure that this value is midway between your maximum and minimum values. If you then decided to apply a range of minus 0.1 and plus 0.1 volume modulation, you would use the values:

Minimum Volume = 0.4

Maximum Volume = 0.6

This gives you a volume range of 0.2 with an average volume of 0.5.

If you wanted the average volume of the sound to be around 0.8, you should ensure that this value is midway between your maximum and minimum values. If you then decided to apply a range of minus 0.2 and plus 0.2 volume modulation, you would use the values:

Minimum Volume = 0.6

Maximum Volume = 1

This gives you a volume range of 0.4 with an average volume of 0.8.

It is important to remember that the AudioSource Volume parameter will go from 0 to 1.

If you type in a number larger than 1, Unity will limit the maximum random volume value to 1.

Mixing using linear volume parameters

Hopefully this all sounds very easy and straightforward in principle. However, in Chapter 3 when introducing the AudioSource Component, I specified that the AudioSource Volume parameter was linear. At this time I did not provide any further info on how this would affect the scaling of the volume control. As I’m sure you’ve worked out by now, the lower the value, the quieter the sound; the bigger the value, the louder the sound.

Most DAWS and mixing desks, however, use a logarithmic application of volume, typically in decibels and commonly abbreviated as dB. A dB is used to express the ratio of one value of a power or root-power quantity to another, using a logarithmic scale. While this may sound quite technical, it simply means that using a mathematical formula, an increase or decrease of 10 dB will have the same effect of doubling or halving the perceived volume. Standard DAWs and mixing desks will use an approximate scale of −80 dB to +20 dB, with 0 dB meaning the sound is not attenuated/turned down or amplified/turned up. Using a logarithmic dB scaling means that no matter if your volume or average volume is set to −40 dB, or any other decibel value, an increase of +3 dB doubles the sound intensity; a 10 dB increase will effectively make the audio be perceived by the listener as sounding twice as loud. This is great for mixing audio, as 1 dB is the smallest change in sound pressure level or volume that the human ear can detect no matter what value the fader has currently been set to, using a common logarithmic range from −80 dB to +20 dB.

The Unity developers, however, have chosen to use a linear scale from 0 to 1 for the Volume parameter. I can only assume the reason they have chosen to implement a linear volume control, using a range from 0 to 1, is to make it much easier for developers to link the volume parameter to be controlled by other game mechanics within Unity. One such example may be if you had a torch mechanic in your game with a battery. If the brightness of the torch was also linked to a linear scale from 0 to 1, it would be relatively easy to write a piece of code to directly control and link the Volume parameter of an AudioSource, and the light Component of the torch, to the remaining battery level. The code could be written relatively easily to increase or decrease the volume and brightness of the torch depending upon the current battery level. If the AudioSource volume control was a linear fader from −80 dB to +20 dB, this would require more complex code and mathematics to convert and link a torch brightness value, using a linear scale, to an AudioSource volume using a logarithmic volume scale.

Using a linear scaling from 0 to 1 for the volume, however, means that a volume range of plus and minus (+/−) 0.1 will have a much bigger perceptive difference in the variation of the volume if your average volume is quieter, for example 0.2, when compared with a bigger or louder value, for example 0.9.

If this is expressed as a ratio or percentage, comparing the average volume to the amount of volume variation using the preceding numbers, then an average volume of 0.2 with a (+/−) volume variation of 0.1 would be entered into the Min and Max Volume parameters on the RandomAudioPlayer script, as 0.1 for the Min Volume and 0.3 for the Max Volume, giving you an average volume of 0.2. If you compare the amount of volume variation to the average volume in this example, using your Min and Max volume variation, you are allowing the sound to half and double in volume from the average. This would be a 1:2 ratio or 100% volume variation.

Using the example of an average volume of 0.9 and the same (+/−) volume variation of 0.1 would result in a perceptively smaller amount of volume variation; entered into the RandomAudioPlayer script, this would be 0.8 and 1 respectively for the Min and Max Volume Variables. This could also be expressed in a percentage ratio of 11.11%. Using these values, you can see that the percentage of volume variation changes considerably depending upon what the average volume is for the same amount of volume variation.

There is a much easier way to maintain the same amount of volume variation when mixing, if you decide that a sound is too loud or too quiet, without resorting to performing complex mathematical equations to calculate Min and Max values.

First, decide on what you think an appropriate average volume should be; for example, you could initially decide that 0.5 seems like it should be ‘in the right ballpark’

Next, decide how much volume variation to apply above and below this average value

To keep things simple, I usually decide upon 10%, 20%, 50%, or 100%.

To calculate 10% volume variation from an average volume of 0.5, simply divide 0.5 by 10, (0.5/10); this would give you a value of 0.05

Take your average volume of 0.5 and deduct 0.05 to give you the Min Volume value of 0.45

Take your average volume of 0.5 and add 0.05 to give you the Max Volume value of 0.55

Now enter these values into the Min and Max Volume Variables on the RandomAudioPlayer script. Your average volume is 0.5 with a (+/−) of 0.05 or a 10% volume variation above and below your average volume.

If you hear the sound within the mix and decide that it needs to be louder, for example, your average volume actually needs to be at 0.7 but you wish to maintain this same 10% volume variation, you would perform the same calculations above using 0.7 as the average volume.

To calculate 10% volume variation from an average volume of 0.7, simply divide 0.7 by 10, (0.7/10); this would give you a value of 0.07

Take your average volume of 0.7 and deduct 0.07 to give you the Min Volume value of 0.63

Take your average volume of 0.7 and add 0.07 to give you your Max Volume value of 0.77

Now if you enter these updated values into the Min and Max Volume Variables on the RandomAudioPlayer script, your average volume is now 0.7 with a (+/−) of 0.07, maintaining a 10% volume variation range above and below your average volume.

By using simple 10%, 20%, 50% volume variations, it makes the maths required to use this strategy much simpler and easier without requiring the use of a calculator or a PhD in mathematics.

As a final example, you could decide to have an average volume of 0.4 with a 30% volume variation (+/−).

Begin by calculating a 10% volume variation from an average volume of 0.4 and divide 0.4 by 10; this would give you a value of 0.04

To work out 30%, multiply 0.04 by 3 to give you 0.12 volume variation

Take your average volume of 0.4 and deduct 0.12 to give you the Min Volume value of 0.28

Take your average volume of 0.4 and add 0.12 to give you your Max Volume value of 0.52

Tip

I have found that you can use larger volume variation percentages such as (+/−) 15% or 20% for sounds that will play infrequently, like Spitter death sounds. Sounds that trigger fairly consistently, like footsteps, usually require a much more subtle amount of volume variation, such as (+/−) 5%. This will sound quite natural while still giving you the desired effect, that is, making your Audio Assets have subtle variations in volume and dynamics when playing back in the game.

You will know if you have set your volume variations using too large of a percentage if the sound does not seem to be balanced in the game. This is often the cause if you notice the sound is sometimes too quiet and sometimes too loud, or it is obvious that the volume is dramatically changing values rather than subtly mimicking natural dynamics.

Min and Max Pitch

The Min Pitch and Max Pitch Variables work using the same principle as the Min and Max Volume Variables. Unity will randomly pick a value between the Minimum and Maximum pitch range and then apply this to the AudioSource.

If you wanted to pitch the sound down to −0.8, you would ensure that this value is midway between your maximum and minimum values. If you then decided to apply 0.1 + and −0.1 pitch modulation, you would use the values:

Minimum Pitch = 0.7

Maximum Pitch = 0.9

This gives you a pitching range of 0.2.

If you wanted to pitch the sound up to 1.3, you would ensure that this value is midway between your maximum and minimum values. If you then decided to apply 0.3 + and – 0.3 pitch modulation, you would use the values:

Minimum Pitch = 1

Maximum Pitch = 1.6

This gives you a pitching range of 0.6.

Tip

I have found in most cases it can sound quite unnatural to apply a large range of pitch processing inside Unity, unless you are applying this for a specific creative reason. As stated in Chapter 3, when introducing the AudioSource Component, Unity applies pitch adjustment by playing the AudioClip file back faster or slower to achieve the change in frequencies. If the Pitch parameter is set to an extreme value, you can hear artefacts introduced to the Audio Asset and you can drastically change the length of the audio file.

When applying pitch variation in a SFX array, a pitch variation of (+/−) 0.1 or (+/−) 0.05 tends to sound quite natural for footsteps while still giving you the desired effect of making your Audio Assets have subtle variations in pitch. Again, sounds that trigger fairly regularly like footsteps usually require a more subtle amount of pitch variation to provide the desired effect consistently. If a sound plays more infrequently, then a larger amount of pitch variation could potentially be used without sounding obvious.

Warning

When using the RandomAudioPlayerScript, it is important to note that adjusting the Volume or Pitch parameters on the AudioSource itself will not have any effect. The RandomAudioPlayer script will inevitably change these values when the sound is played according to the Min and Max Pitch and Volume controls in the RandomAudioPlayerScript.

Play Delay

The Play Delay Variable will wait the amount of time that corresponds to the value entered in the number variable, before then playing the Audio Asset.

Tip

The value you enter is in seconds.

To add a delay of half a second before playing the sound, you would enter a value of 0.5; for one second, a value of 1; and for a delay of five seconds, you would enter 5. In the majority of circumstances, you will want the sound to play immediately; in this case, you would use a value of 0.

Default Bank

As you have probably noticed, the AudioSource Component by default only gives you one AudioClip slot to select a single Audio Asset to play. Using the Bank function, you can expand this to as many Audio Asset variations as you feel are necessary to stop the sound becoming repetitive.

A Bank, or Array, as it is also called, is used to allow you to add in multiple variations of the same type of Asset, for example if you wanted to have five footsteps sounds. This script has been coded to randomly select an Asset from the Array when the AudioSource has been triggered to play.

Figure 9.1.2 Random Audio Player AudioClips Bank

The Default Bank is used, as its name suggests, by default or automatically. You type in the amount of Audio Assets you have created to add in the number of AudioClip variables you require. In Figure 9.1.2, four different variations of the Chomper enemy attack voice SFX have been created and added to the AudioClip variables.

When the Chomper Enemy attacks, the code in the game will trigger the Chomper attack AudioSource. The RandomAudioPlayer script will then randomly pick one of the four available Audio Assets, place this in the AudioClips section of the AudioSource, and then play the sound.

Tip

It is a skill to create different versions of a single sound that have enough variation to maintain immersion and not sound repetitive to the player, without sounding like completely different sound sources. The notes from Chapters 2 and 3 offer techniques and guidance on maintaining cohesive sound design between variations of Assets.

Sounds that repeat more frequently often require more variations compared with those that play less frequently. An example in this particular project is Ellen’s footsteps. A sound like this, which repeats very often, would require approximately ten or twenty variations for each surface she can stand on (i.e. stone, grass etc.) as the player will hear these sounds hundreds of times in a single level. In contrast, Ellen’s death voice SFX may only require two or three variations, as this should hopefully play back one to five times throughout a level for an average player.

Overrides

The Overrides parameter works alongside the Default Bank and allows for additional groups of sounds to be added to the script. This is only used in particular mechanics that will be highlighted, such as Ellen’s footsteps to allow for different walking/running SFX and to trigger different sounds corresponding to the different surfaces she walks/runs on.

In Figure 9.1.3, I have reduced the amount of Audio Assets to 4 for the purposes of the screenshot.

Figure 9.1.3 Random Audio Player Overrides

Prefab Overrides

You may find it helpful to read back through Chapter 5 to re-familiarise yourself with how Prefabs function and using the Override function.

As also discussed in Chapter 5, you may find that when attempting to restructure or remove GameObjects that are part of a Prefab structure, the following warning message in Figure 9.1.4 will be displayed in Unity.

Figure 9.1.4 Prefab Restructuring Warning in Hierarchy

If this message appears, you will be required to open up the Prefab and edit it directly in Prefab Editing Mode. You can do this by clicking on the Open Prefab button shown in the error message in Figure 9.1.5. Alternatively, you could right click on the GameObject in the Hierarchy and select Open Prefab Asset, or click on the arrow as indicated in Figure 9.1.5. This will open up the Prefab in its own temporary Unity Scene, allowing you to make any modifications you may want. After clicking on the left arrow, your changes will be applied automatically and Unity will load the current Scene file again.

Figure 9.1.5 Opening Prefab Asset in Prefab Editing Mode

Figure 9.1.6 Saving Prefab Modifications

Ellen

Ellen is the character the player controls throughout this game. She has a number of SFX, including footsteps, weapon SFX from her staff, and a number of vocal grunts/strains when performing actions such as jumping, attacking, or getting injured.

Figure 9.2.1 Ellen Character Model

The majority of Ellen’s AudioSources can be found on the PlayerController Script that is located on the Parent Ellen GameObject in the Hierarchy. They can be viewed by pressing the icon to view all of the dropdowns that are part of the References Variable.

Figure 9.2.2 Ellen Player Controller Script with Assigned Random Audio Player GameObjects

Ellen footsteps

Ellen’s footsteps should be created as One Shot Audio Assets, with a single footstep per audio file.

If you click on the FootstepSource Variable on the PlayerController script, Unity will highlight where this AudioSource exists in the Hierarchy.

Alternatively, it can be found using the Hierarchy path:

Ellen > AudioSources > FootstepSource

Figure 9.2.3 Ellen FootstepSource RandomAudioPlayer AudioSource GameObject in Hierarchy and Inspector

Clicking on the FootstepSource as highlighted in yellow within Unity will show you the controls for the AudioSource and RandomAudioPlayer script.

As previously covered, Ellen’s footsteps use a Default Bank for a group of Audio Assets that will play if the game has not been explicitly told to use any of the Override Banks.

The Overrides contain additional Banks for Walk and Run for alternative surfaces such as Earth, Grass, Puddles, and Stone.

In the Materials tab, you can see which art materials each of these Banks has been linked to. Setting which material is used on which piece of floor is usually one of the artist’s responsibilities, as VFX often use a similar system as audio to play back the correct SFX for each surface. In this project, each surface in the game has already been set up with a corresponding footstep allocation.

You will need to go through each of the Elements within the script, typing in how many of each footstep SFX you have created and adding these to the associated AudioClips for each Bank.

Figure 9.2.4 Ellen Footstep Overrides on RandomAudioPlayer Script

After adding all of your Audio Assets, you can then enter your own values for Min and Max Volume/Pitch.

Be aware that these values are shared between all Footstep Banks. If you want the running SFX to be slightly louder than walking SFX, you will have to adjust the volume balance manually within the sound Assets by normalising these to a slightly lower/quieter volume. This is because in this script, you are not given control over each individual footstep surface type or between walking and running. All footsteps will share the same Min Volume and Max Volume parameters at the top of the RandomAudioPlayer script.

Ellen hurt voice

Ellen’s hurt voice should be created as One Shot Audio Assets, with a single vocalisation per audio file.

This GameObject is for Ellen’s vocal SFX after being attacked by an enemy.

View the PlayerController Script in the Inspector; this can be located on the main Ellen GameObject in the Hierarchy. Finally, click on the HurtSource Variable in the Inspector or, alternatively, directly find the HurtSource AudioSource GameObject in the Hierarchy using the following path:

Ellen > AudioSources > HurtSource

You can add in all of your Audio Assets to the Clips Variables and set the Minimum and Maximum Pitch and Volume of the AudioSource using the RandomAudioPlayer script.

Figure 9.2.5 Ellen HurtSource RandomAudioPlayer AudioSource GameObject

Ellen landing/roll source

This GameObject is for a footstep or rolling type SFX when Ellen first hits the ground after jumping or falling. It uses the exact same principles as the Ellen Footsteps implementation for the various Banks and Materials; the Land Idle, Land Walk, and Land Run Banks SFX should be created as One Shot Audio Assets, with a single footstep or rolling type SFX per audio file.

Select the PlayerController Script that is located on the main Ellen GameObject in the Hierarchy and click on the LandingRollSource Variable, or alternatively find in the Hierarchy:

Ellen > AudioSources > LandingRollSource

Ellen voice when landing, dying, attacking, and jumping

The following GameObjects all use the exact same implementation as the Ellen hurt voice implementation. They are for the Grunts/Emotes/Voice-Over when she performs these actions.

As with Ellen’s vocalisations when hurt, these should be created as One Shot Audio Assets, with a single vocalisation per audio file.

Select the PlayerController Script that is located on her main Ellen GameObject in the Hierarchy and click on the EmoteLanding, EmoteDeath, EmoteAttack, and EmoteJump Variables, or alternatively find in the Hierarchy:

Ellen > AudioSources > EmoteLanding

Ellen > AudioSources > EmoteDeath

Ellen > AudioSources > EmoteAttack

Ellen > AudioSources > EmoteJump

Ellen staff weapon

Ellen has two SFX for her Staff; one is the SFX that will play when she swings it and the other is an impact SFX that will play when it collides with a GameObject such as an Enemy or Breakable GameObject. Both should be created as One Shot Audio Assets, with a single SFX per audio file.

Even though the player can click the ‘attack button’ repeatedly and perform a combo move, each time the staff is swung, this mechanic has been set up to play a singular One Shot Audio Asset, rather than an audio file containing up to three swing sounds within a single Audio Asset.

The GameObjects for this Sound are located on the: Ellen > Staff > Melee Weapons (Script).

Clicking on the Hit Audio or Attack Audio Variables will highlight the AudioSources and RandomAudioPlayer scripts.

Alternately, locate in the Hierarchy:

Ellen > Staff > AudioSource > HitSound

Ellen > Staff > AudioSource > SwingSound

Figure 9.2.6 Ellen Staff Weapon HitSound and SwingSound GameObjects in Hierarchy

Ellen splash SFX

A splash SFX can be heard when Ellen falls into the water in Level01 and the acid-type liquid in Level02. These splash SFX should be created as One Shot Audio Assets, with a single splash per audio file.

This mechanic was created using Trigger Areas placed over the liquid hazard in the game; when the playable character falls into or collides with the Box Collider Components, the DeathVolume script will trigger the SFX to play from the playable character’s current position in the game.

Begin by selecting the DeathVolume GameObject on the root of the Hierarchy in Level01.

The DeathVolume script contains a single variable called Splash SFX.

Clicking on the SplashAudio Variables will highlight the SplashAudio GameObject containing a Transform, AudioSource, and RandomAudioPlayer script Components.

Alternatively, locate the GameObjects in the Hierarchy:

(Level01 Scene) LVL1_DeathVolume > DeathVolume > SplashAudio

(Level01 Scene) LVL2_DeathVolume > DeathVolume1 > SplashAudio

(Level02 Scene) LVL2_DeathVolume > DeathVolume2 > SplashAudio

(Level02 Scene) LVL2_DeathVolume > DeathVolume3 > SplashAudio

Figure 9.2.7 SplashAudio GameObject Assigned to Splash SFX Variable on Death Volume Script Located on Lvl1_DeathVolume GameObject

Add your AudioClip Asset/s to the RandomAudioPlayer script Component and set the Min and Max Pitch and Volume parameters.

You will notice that the Transform position of the Splash Audio GameObject will change and update its position when Ellen jumps or falls into a water/acid hazard. The DeathVolume script will take Ellen’s current position information and apply this to the SplashAudio GameObject when Ellen passes through the Box Collider.

You will also notice that this mechanic is not using a Prefab; this means each SplashAudio GameObject will require you to add in the AudioClip/s and set the Min/Max Volume and Pitch parameters separately. This will allow you to use different SFX for the water in Level01 and the acid in Level02.

Chomper enemy

The Chomper is the first enemy the player will encounter in the game. It has simple AI behaviour that will make the Chomper stay in one area until the player approaches it. At this point, the Chomper will begin chasing Ellen, and when it is close enough will begin jumping to attack her. If Ellen runs far enough away, the Chomper will stop chasing her and return to its original location.

All the Chomper SFX for footsteps, attacks, deaths, and grunts should be created as One Shot Audio Assets, with a single vocalisation or SFX per audio file.

Figure 9.3.1 Chomper Enemy Model

The majority of the Chomper’s AudioSources can be found on the ChomperBehavior Script that is located on the Parent Chomper GameObjects in the Hierarchy.

Enemies > Chomper > AudioSource

Figure 9.3.2 Chomper RandomAudioPlayer AudioSource GameObjects Assigned to Chomper Behaviour Script

The following GameObjects all use the exact same implementation as the Ellen hurt voice implementation, using an AudioSource and RandomAudioPlayer script.

Select the ChomperBehavior Script that is located on the main Chomper GameObject in the Hierarchy and click on the AttackSource, FrontFootstepSource, BackFootstepSource, HitSource, GruntSource, DeathSource, and SpottedSource Variables, or alternatively find in the Hierarchy:

Enemies > Chomper > AudioSources > AttackSource

// This is played when the Chomper performs its lunging attack.

(This sound will begin to play as soon as the Chomper attack animation begins as it leans back before lunging at Ellen. If you want to include a build-up sound before the main jump, then add this into your audio file. If you just want to include the main lunge, then consider adding a value of 0.5 to the Play Delay on the AttackSource RandomAudioPlayer.)

Enemies > Chomper > AudioSources > FrontFootstepSource

Enemies > Chomper > AudioSources > BackFootstepSource

// This is used for the Chomper’s Footsteps and is split into front and back legs.

Enemies > Chomper > AudioSources > HitSource

// This is played immediately when the Chomper is attacked by Ellen.

Enemies > Chomper > AudioSources > GruntSource

// This is used for the general breathing/grunting sounds emitted from the Chomper during non-attack, idle animations.

Enemies > Chomper > AudioSources > DeathSource

// This is played when the Chomper is defeated and dies/disappears.

Enemies > Chomper > AudioSources > SpottedSource

// This is played when the Chomper first spots the Player and enters attack mode.

Spitter enemy

The Spitter is the second enemy type the player will encounter in the first level of the game. It has simple AI behaviour that will allow the Spitter to fire projectiles at Ellen when the player is inside its attack range.

Like the Chomper, all the Spitter SFX should be created as One Shot Audio Assets, with a single vocalisation or SFX per audio file.

Figure 9.4.1 Spitter Enemy Model

The majority of the Spitter’s AudioSources can be found on the SpitterBehavior Script, which is located on the main Spitter GameObjects in the Hierarchy.

Enemies > Spitter > AudioSource

Figure 9.4.2 Spitter RandomAudioPlayer AudioSource GameObjects Assigned to Spitter Behaviour Script

The following GameObjects all use the exact same implementation as the Chomper enemy implementation, consisting of an AudioSource and RandomAudioPlayer script.

Select the SpitterBehavior Script, located on the main Spitter GameObject in the Hierarchy, and click on the AttackSource, FrontFootstepSource, BackFootstepSource, HitSource, GruntSource, DeathSource, and SpottedSource Variables, or alternatively find the GameObjects in the Hierarchy:

Enemies > Spitter > AudioSources > AttackSource

// This is played when the Spitter launches its projectile.

Enemies > Spitter > AudioSources > FrontFootstepSource

Enemies > Spitter > AudioSources > BackFootstepSource

// This is used for the Spitter’s Footsteps and is split into front and back legs.

Enemies > Spitter > AudioSources > HitSource

// This is played immediately when the Spitter is attacked by Ellen.

Enemies > Spitter > AudioSources > GruntSource

// This is used for the general breathing/grunting sounds emitted from the Spitter during Idsle animations.

Enemies > Spitter > AudioSources > DeathSource

// This is played when the Spitter is defeated and dies/disappears.

Enemies > Spitter > AudioSources > SpottedSource

// This is played when the Spitter first spots the Player and goes into attack mode.

Spitter projectile SFX

The Spitter has one additional sound for the projectile it throws at Ellen. The variable for the Prefab it spawns can be found on the LowerMouth of the Spitter and is triggered by the RangeWeapon script.

Enemies > Spitter > Skelton > Root > Core > Chest > LowerMouth

Figure 9.4.3 Spitter Range Weapon Script Containing Spit Prefab Variable

Clicking on this Spit Drop Target will direct you to the Spit Prefab location in the Project Panel.

Alternatively, it can be found using the following Project Panel Path:

Assets > 3DGameKit > Prefabs > VFX > Characters > Enemies > Spitter

Figure 9.4.4 Spit Prefab Location in Project Panel

If you select this Prefab from the Project Panel and double click on it, it will open up the Spit Prefab Asset for editing. You will see two AudioSources; Travel is for the projectile while it is in the air and Explosion is when it impacts upon the ground or Ellen.

(Spit Prefab) Spit > AudioSources > Travel

(Spit Prefab) Spit > AudioSources > Explosion

The Explosion GameObject uses the same RandomAudioPlayer script you have seen used in the majority of examples.

The Travel GameObject does not use this script and has Play On Awake activated to ensure the sound begins playing as soon as the projectile has been launched at the player.

Figure 9.4.5 Spit Travel AudioSource GameObject

Grenadier enemy

The Grenadier is the Boss enemy the player will encounter at the end of each level. It has a more sophisticated AI than the previous enemies. It has several attacks it can unleash on the player, has more health hit points, and can only be attacked from behind.

Figure 9.5.1 Grenadier Enemy Model

The majority of the Grenadier’s AudioSources can be found on the GrenadierBehavior Script located on the main Grenadier GameObject in the Hierarchy:

Enemies > Grenadier

Figure 9.5.2 Grenadier RandomAudioPlayer AudioSource GameObjects Assigned to Grenadier Behaviour Script

The following drop targets all use the exact same implementation as the Spitter implementation, using an AudioSource and RandomAudioPlayer script.

Select the GrenadierBehavior Script located on the main Grenadier GameObject in the Hierarchy and click on the DeathPlayer, DamagePlayer, FootstepPlayer, ThrowPlayer, and PunchPlayer Variables, or alternatively find in the Hierarchy.

Enemies > Grenadier > SoundPlayers > DeathPlayer

// This is played when the Spitter is defeated and dies/disappears.

Enemies > Grenadier > SoundPlayers > DamagePlayer

// This is played immediately when the Spitter is attacked by Ellen.

Enemies > Grenadier > SoundPlayers > FootstepPlayer

// This is played for the Spitter’s Footsteps.

Enemies > Grenadier > SoundPlayers > ThrowPlayer

// This is played immediately when the Grenadier launches its projectile.

Enemies > Grenadier > SoundPlayers > PunchPlayer

// This is played when the Grenadier begins its melee/punching attack.

Grenadier projectile SFX

The Grenadier has additional sounds for the projectile it throws at Ellen. These work in a similar way to the Spitter projectile. This drop target for the Prefab it spawns can be found on the Grenadier_Sphere and is triggered by the RangeWeapon script.

Enemies > Grenadier > GrenadierSkelton > Grenadier_Root > Grenadier_ Hips > Grenadier_Sphere

Clicking on this EnergyGrenade Drop Target will point you to the Prefab location in the Project Panel.

Alternatively, it can be found using the following Project Panel Path:

Assets > 3DGameKit > Prefabs > VFX > Characters > Enemies > Grenadier

Figure 9.5.3 EnergyGrenade Prefab Location in Project Panel

If you select this Prefab from the Project Panel and double click on it, it will open up the EnergyGrenade Prefab Asset for editing. You will see two AudioSource GameObjects; ExplosionPlayer is for the projectile when it explodes and Bounce is when it bounces and impacts upon the ground or Ellen.

(EnergyGrenade Prefab) EnergyGrenade > AudioPlayer > ExplosionPlayer

(EnergyGrenade Prefab) EnergyGrenade > AudioPlayer > BouncePlayer

The ExplosionPlayer and BouncePlayer GameObjects use the same RandomAudioPlayer script you have seen used in the majority of examples.

Grenadier shield SFX

The Grenadier can produce a VFX shield, which makes it temporarily invulnerable and will injure the player if they collide with it.

Tip

You should attempt to adjust the timing within your One Shot Audio Assets to correspond with the length/timing of the visual effects. It may help to quickly capture some gameplay footage of this mechanic to use as reference when designing the sound.

The variable for the AudioSource it uses can be found on the Charge GameObject in the Hierarchy on the AudioPlayerOnEnable script.

Enemies > Grenadier > GrenadierSkelton > Grenadier_Root > Grenadier_Hips > Grenadier_Sphere > Charge > AudioPlayerOnEnable (Script)

Figure 9.5.4 Grenadier ShieldUpPlayer GameObject Assigned to Audio Player on Enable Script

This Player Variable links to the ShieldUpPlayer AudioSource, which can be found in the Hierarchy:

Enemies > Grenadier > SoundPlayers > ShieldUpPlayer

Grenadier break apart during death animation SFX

The Grenadier plays a unique animation when it has been defeated, whereby it will break apart into many pieces. Like the Grenadier Shield mechanic, you should create a One Shot Audio Asset to correspond with the length and timing of the visual effects in the animation.

The code logic to trigger this animation uses an EffectEvents script found on the main Parent Grenadier GameObject to enable a Child GameObject called DeathEffect.

Figure 9.5.5 Grenadier Death Event Located on Effect Events Script Linked to DeathEvent GameObject

The AudioSource for this break apart death animation can be found using the following path in the Hierarchy:

Enemies > Grenadier > DeathEffect > DestroyerPlayer

The DestroyerPlayer AudioSource GameObject does not require a drop target/variable or use a script. Instead, it uses the Parent/Child relationship in the Hierarchy, as it is enabled by default and has Play On Awake activated. This means that the sound will begin playing as soon as the DeathEffect GameObject is enabled/activated by the EffectEvents script when the Grenadier is defeated.

Figure 9.5.6 Grenadier DestroyPlayer AudioSource GameObject in Hierarchy

5 quick tips

The Ellen and Enemy GameObjects all use Prefabs. Applying the audio additions and changes you make will save you an enormous amount of time. By doing this, you do not have to add in the AudioClips and mix the settings for each individual AudioSource or RandomAudioPlayer script on every enemy. You need only do this for one and apply the change to the rest of the linked Prefabs in the game.

I would advise starting the Chapter 9 practical tasks by creating, implementing, and mixing Ellen’s footsteps. Having these footsteps and the ambience well balanced will make getting a rough volume balancing of the other mechanic’s SFX much easier.

When creating the Chomper, Spitter, and Grenadier SFX, try recording then heavily processing your own voice. To add in an additional expression, you could also add in an animalistic sound design layer.

I would advise potentially adding in an additional Chomper or Spitter enemy somewhere near the start of the level. This will let you add in your own Audio Assets and get rough mix balance in place before applying your changes to the Prefab. This may be much quicker than playing through the level to reach these enemies. (Don’t forget to delete this additional enemy from the Hierarchy when you are finished.)

Remember when using the RandomAudioPlayer script that the Volume and Pitch settings on the actual AudioSource will be overwritten when the AudioSource begins to play the AudioClip.

Tip

You can use a RandomAudioPlayer Component, AudioSource GameObject within an InteractOnTrigger script, by setting the function to PlayRandomClip. This command will tell the RandomAudioPlayer script to play the AudioSource, selecting random Audio Assets, random pitch, and random volume.

Chapter 9 practical tasks

The practical task for this chapter is to make and implement your own SFX for these character mechanics.

Adding SFX to Ellen’s footsteps

Adding SFX for Ellen’s emotes

Adding SFX for Ellen’s Staff Weapon

Adding SFX for a Splash SFX when landing in water/acid

Chomper Enemy vocalisations

Chomper Enemy footsteps

Spitter Enemy vocalisations

Spitter Enemy footsteps

Spitter Projectile SFX

Grenadier Vocalisations

Grenadier Shield SFX

Grenadier Damage SFX

Grenadier Punch SFX

Grenadier Projectile SFX

Grenadier Death SFX

You can influence how dangerous the player perceives these enemies to be through your sound design and mix choices. Use the Game Audio Design documentation you created during the Chapter 6 practical task to inform your creative decisions.

I would strongly advise you to begin using the Silent version of the game project; doing this, you will be required to import and assign all of your own AudioClips to the existing RandomAudioPlayer scripts/AudioSources as indicated in this chapter.

I would advise you to start with the Silent project, rather than taking the With Audio version of the project and replacing the existing audio files using the Windows Explorer/Apple Finder method, as used for the footsteps in the earlier Viking Village project. This will give you a much deeper understanding of the overall Game Audio process and the Components that will be required. This will be massively beneficial if, in the future, you begin working on a game as a Sound Designer that is in active development as there won’t be any existing audio files for you to replace.

10 Audio Implementation of game mechanics and cutscenes

DOI: 10.4324/9781003055167-10

This chapter will continue to explore the implementation and setup of a number of mechanics in the 3D GameKit.

How to trigger audio on:

Destructible Objects

Health Chests

Collect Staff SFX

Doors/Floor Switches/Crystals

Moving Platforms

Gateway at end of Level01

Spaceship at the end of Level02

You will explore how each of these SFX has been implemented in the 3D GameKit. In Chapter 13, you will revisit some of these mechanics and explore how you could improve upon this initial Audio Implementation. You can assume that all Audio Assets in this chapter should be created as One Shot Audio Assets, with one SFX per audio file unless otherwise specified.

Destructible stone chests

There are a number of stone chests that Ellen can destroy with her Staff Weapon throughout the level.

Stone boxes – blue light

These are the most common destructible GameObjects found throughout the levels and are sometimes placed so the player has to smash them to gain access to areas.

Figure 10.1.1 Destructible Stone Chest Model

There are three different sized stone boxes/chests that should have unique audio assets and mix settings going from largest/loudest, medium, and smallest/quietest.

Select one of the destructible boxes of each size featuring a blue light in the Scene View or the Hierarchy location and Open the Prefab Asset using the Inspector.

Level01Gameplay > Destructibles > DestructibleBoxLarge

Level01Gameplay > Destructibles > DestructibleBoxMedium

Level01Gameplay > Destructibles > DestructibleBoxSmall

Figure 10.1.2 DestructibleBox Hierarchy Location

The first Child GameObject inside the Prefab is called DestructibleBox. It has a Damageable script with the AudioSource hooked into the On Death () function and set to RandomAudioPlayer.PlayRandomClip.

The AudioSource GameObject is located at the bottom of the Hierarchy and is called Audio.

Figure 10.1.3 Audio GameObject Containing RandomAudioPlayer and AudioSource Assigned to Damageable On Death () Event

As with the majority of these mechanics, it uses the RandomAudioPlayer script and requires a bank of One Shot Audio Assets.

Figure 10.1.4 Audio GameObject with AudioSource and RandomAudioPlayer Components

As these use Prefabs, if you Open and Edit the Prefab, or use the Overrides feature, the changes you have made will be applied to all Destructible Boxes in the game across both levels.

Health Chests – yellow light

There are few breakable chests with a yellow glowing icon on them that can be found in both levels. These chests will fully restore the player’s health when activated.

Figure 10.1.5 HealthCrate Model

Select one of the destructible boxes with a yellow light.

Level01Gameplay > HealthCrates > HealthCrate

Level02Gameplay > HealthCrates > HealthCrate

Figure 10.1.6 HealthCrate Hierarchy Location

This HealthCrate mechanic has two variables; one will play a SFX when the chest has been opened and the other will stop the looped ambient SFX emanating from the chest before it has been opened.

The opening SFX should be created as singular One Shot Audio Assets; the looped ambient SFX, as the name suggests, should be created as a Seamless Looping Audio Asset.

Both variables for the AudioSources can be found on the Parent GameObject called HealthCrate, attached to the On Enter () function of the InteractOnTrigger script.

The AudioSource on the Parent HealthCrate GameObject has been set to Play On Awake and Loop to ensure that the ambient Health Crate sound starts playing automatically when the chest is unopened. It will then continue to Loop until the chest has been opened, when the playable character enters the Trigger Area Collider, at which point it will then stop playing.

Figure 10.1.7 HealthCrate Unopened Looping AudioSource GameObject

The second variable in the list is called HealthCrate (AudioSource) and is linked into this same Parent HealthCrate GameObject AudioSource. It uses the AudioSource.Stop command to stop the ambient SFX in the AudioSource playing when Ellen has entered the Box Collider.

The third variable on the list is called OpenAudio (AudioSource) and is linked into the bottom Child AudioSource GameObject called OpenAudio. This uses the AudioSource.Play command to play the AudioClip for the opening SFX on the OpenAudio AudioSource. To add in your Audio Asset for this mechanic, add this to the AudioClip parameter directly on the OpenAudio AudioSource.

Figure 10.1.8 HealthCrate OpenAudio GameObject and InteractOnTrigger Assignments

The additional variables on the InteractOnTrigger script have been set up to play the animation of the Health Crate opening and to restore Ellen’s health to full.

Collect Staff SFX

Ellen starts off the first level without any weapons or means to defend herself against the enemies. A staff weapon can be found on a pedestal just after making the jump across from the starting area into the main section of the map.

Figure 10.2.1 Staff Model

An AudioSource GameObject has been implemented to play a One Shot collect SFX when Ellen has successfully acquired the staff weapon.

It can be found in the Level01 Hierarchy.

Level01Gameplay > WeaponPedestal > StaffTakeTrigger > On Enter () > WeaponPedastal

Figure 10.2.2 WeaponPedestal GameObject with InteractOnTrigger Script

The WeaponPedestal AudioSource has been set to Play when the Player character has entered the Trigger Area’s Sphere Collider, along with disabling the visual model of the Staff and setting the Pickup GameObject to active. Clicking on the WeaponPedestal Variable shown in the InteractOnTrigger script will highlight the WeaponPedestal AudioSource in yellow on the Hierarchy.

Alternatively, locate the GameObject in the Hierarchy using the following path:

Level01Gameplay > WeaponPedestal > WeaponPedestal

Figure 10.2.3 WeaponPedestal Child GameObject with AudioSource

Replace the Audio Asset in the AudioClip parameter of the AudioSource. Please also note that Play On Awake has not been Activated as this sound is being triggered using the AudioSource.Play command on the InteractOnTrigger Script.

Door pressure pads and opening animations

There are a number of closed doors that block the player’s progress through the levels. The first of these doors in Level01 requires the player to find and stand on a pressure pad switch located nearby. The second and final door in Level01 requires the player to collect three floating crystals to activate the door opening revealing the Grenadier enemy.

The second level follows a very similar structure; the player is required to stand on pressure pad switches and collect crystals to activate the door opening animations to progress through the level. All of the pressure pads and door opening SFX require a One Shot Audio Asset.

Figure 10.3.1 Door Pressure Pad Model

Door pressure pads

There are a number of pressure pads in the game that, when stood upon, trigger an animation featuring a door that opens to allow the player entry to a previously inaccessible part of the level. The first switch can be found in Level01 on the right-hand side of the large closed stone door, in the middle of a small alcove surrounded by a number of enemies. The second switch can be found near the end of the level on a tall platform, again on the right-hand side of the second large stone door.

An On Send Audio Variable has been included on the SendOnTrigger script to play a switch/clunk-type SFX when Ellen enters the Box Collider positioned on the switch. The ActivateAudio AudioSource is triggered by code so does not need Play On Awake Activated.

The AudioSource can be found on the Send On Trigger Enter script found on each of the Parent GameObjects for the Pressure Pad Switches.

Level01Gameplay > PressurePad > PressurePad1 > ActivateAudio

Level01Gameplay > PressurePad > PressurePad2 > ActivateAudio

Level02Gameplay > PressurePad > PressurePad1 > ActivateAudio

Level02Gameplay > PressurePad > PressurePad2 > ActivateAudio

Figure 10.3.2 PressurePad GameObject Hierarchy Locations with Send On Trigger Enter Scripts

These GameObjects are not Prefabs as they are set up to control different door opening animations.

You will need to add in your Audio Asset to each AudioClip parameter on the AudioSources individually across both levels, as these GameObjects are not linked via Prefabs.

Door opening SFX

When Ellen enters the Box Collider positioned on the switch or has collected all the Crystal GameObjects, a short animation/cutscene will play featuring one of the huge stone doors opening.

Figure 10.3.3 Door Model

The SimpleTranslator script has been coded to play the AudioClip added to the AudioSource for the DoorHuge Parent GameObjects, using the On Start Audio Variable when Ellen enters the Box Collider attached to the relevant switch or Crystal.

As this AudioSource will be triggered to play by the SimpleTranslator script alongside the animation, it does not need the Play On Awake parameter Activated.

The AudioSource can be found next at the bottom of the Inspector under the Simple Translator script Component found on each of the Parent GameObjects for the huge doors.

(Level01 Scene) Level01Gameplay > Doors > DoorHuge1

(Level01 Scene) Level01Gameplay > Doors > DoorHuge2

(Level01 Scene) Level01Gameplay > Doors > DoorHugeGrenadier

(Level02 Scene) Level02Gameplay > Doors > Door1

(Level02 Scene) Level02Gameplay > Doors > Door2

(Level02 Scene) Level02Gameplay > Doors > Door3

(Level02 Scene) Level02Gameplay > Doors > Door4

Figure 10.3.4 Door Opening GameObject Hierarchy Location and AudioSource Component

Collect crystal SFX

The final door in the level blocking access to the Grenadier boss in Level01 requires three crystals to be collected before the door will open. The player is also required to collect a crystal in Level02 to open a door.

Figure 10.4.1 Crystal Model

There are three different AudioSources and Audio Assets required for this mechanic; there is a One Shot collection SFX, a Seamless Looping ambience sound emanating from each crystal before it has been collected, and a separate Seamless Looping ambience after it has been collected.

When the crystal is collected by the playable character stepping inside the Collider, the original looping ambient SFX will stop playing and a separate/different looping ambience will begin to play. This is a good opportunity to introduce positive reinforcement for the player and will correspond with the visual change of the crystal from red to white. The ‘before collection’ looping SFX can be mixed positionally using a larger Max Distance in combination with the 3D Spatial Blend setting on the AudioSource; this will help guide the player towards the location of the crystal. To achieve this, the Min and Max Distance parameters would be set to get louder the closer the player is to the target crystal. By listening to the volume of the sound effect, the player can work out if they are getting closer or further away from the crystal. The ability to then stop this ambient SFX and to play a new, different SFX on a separate AudioSource will allow you to provide feedback to the player that the crystal has been collected. The Audio Asset could be created not only to correspond with the visual colour change of the crystal GameObject in the game but also to sound somehow ‘less important’ as it has now been collected and is no longer the player’s focus. This effect could be enhanced by then setting the ‘after collection’ looping AudioSource to use a smaller Max Distance, as the player no longer needs to be guided towards the crystal.

Crystal collect SFX

The AudioSources for each of the Collect Crystal SFX can be found on each of the SwitchCrystal GameObjects using the following Hierarchy path:

(Level01 Scene) Level01Gameplay > Crystals > SwitchCrystal1 > CrystalCollectAudio

(Level01 Scene) Level01Gameplay > Crystals > SwitchCrystal2 > CrystalCollectAudio

(Level01 Scene) Level01Gameplay > Crystals > SwitchCrystal2 > CrystalCollectAudio

(Level02 Scene) Level02Gameplay > Crystals > SwitchCrystal1 > CrystalCollectAudio

The script Component that triggers this CrystalCollectAudio AudioSource can be found on the Parent SwitchCrystal GameObjects and has been assigned to the SendOnTriggerEnter script Component using the On Send Audio Variable.

Figure 10.4.2 SwitchCrystal GameObjects Containing Send On Trigger Enter Scripts with CrystalCollectAudio GameObjects Assigned to On Send Audio Variable

You should create a singular One Shot Audio Asset for this collection SFX. The AudioSource should NOT be set to Play on Awake or Loop.

Crystal ambient loops

AmbientAudioBeforeCollection and AmbientAudioAfterCollection AudioSources have been set up to play spatially in 3D, radiating outwards from the crystal before the playable character enters the Box Collider to collect it.

The AmbientAudioBeforeCollection AudioSources have been set to Loop and also Play On Awake so that they start playing when the level begins.

The AudioSources for each of the Before Collecting Crystal SFX can be found on each of the SwitchCrystal GameObjects using the following Hierarchy path:

(Level01 Scene) Level01Gameplay > Crystals > SwitchCrystal1 > AmbientAudioBeforeCollection

(Level01 Scene) Level01Gameplay > Crystals > SwitchCrystal2 > AmbientAudioBeforeCollection

(Level02 Scene) Level01Gameplay > Crystals > SwitchCrystal2 > AmbientAudioBeforeCollection

(Level01 Scene) Level02Gameplay > Crystals > SwitchCrystal1 > AmbientAudioBeforeCollection

The AmbientAudioAfterCollection AudioSources have been set to Loop but NOT Play On Awake so that they do not begin playing until after the crystal has been collected.

The AudioSources for each of the After Collecting Crystal SFX can also be found on each of the SwitchCrystal GameObjects using the following Hierarchy path:

(Level01 Scene) Level01Gameplay > Crystals > SwitchCrystal1 > AmbientAudioAfterCollection

(Level01 Scene) Level01Gameplay > Crystals > SwitchCrystal2 > AmbientAudioAfterCollection

(Level02 Scene) Level01Gameplay > Crystals > SwitchCrystal2 > AmbientAudioAfterCollection

(Level02 Scene) Level02Gameplay > Crystals > SwitchCrystal1 > AmbientAudioAfterCollection

The script Component that stops the CrystalCollectAudio AudioSources playing and starts the AmbientAudioAfterCollection AudioSources playing can be found on the Parent SwitchCrystal GameObjects. These AudioSources have been assigned to the InteractOnTrigger script Component using the On Enter parameter variable.

Figure 10.4.3 SwitchCrystal AmbientAudioBeforeCollection and AmbientAudioAfterCollection GameObjects Assigned to InteractOnTrigger script On Enter () Variables

The AmbientAudioBeforeCollection AudioSource has been configured to stop playing, and the AmbientAudioAfterCollection AudioSource has been configured to start playing.

You should create a single Looping Audio Asset for each of the ‘before’ and ‘after’ crystal collection AudioSources and add these to the respective AudioClip parameters.

Moving platforms

Level02 features a number of platforms. The player will need to use these to avoid the acid pools or rivers to jump across and reach the next section of the level.

Figure 10.5.1 Moving Platform Model

All the moving platforms described in this chapter require a Seamless Looping Audio Asset.

An AudioSource GameObject has been added as a Child of each of the floating or moving platforms’ Body GameObject. This use of the Parent/Child Hierarchy relationship, as described during Chapter 1, is to ensure that the sound will move alongside the platform in the game, without the need for a separate audio specific animation.

Locate the AudioSource for the platforms that rise up and down using the following Hierarchy path:

Level02Gameplay > MovingPlatforms > RisingPlatform1 > Rising PlatformAudioLoop

Level02Gameplay > MovingPlatforms > RisingPlatform2 > Rising PlatformAudioLoop

Level02Gameplay > MovingPlatforms > RisingPlatform3 > Rising PlatformAudioLoop

Locate the AudioSource for the platforms that float using the following Hierarchy path:

Level02Gameplay > MovingPlatforms > RisingPlatform1 > Floating PlatformAudioLoop

Level02Gameplay > MovingPlatforms > RisingPlatform2 > Floating PlatformAudioLoop

Level02Gameplay > MovingPlatforms > RisingPlatform3 > Floating PlatformAudioLoop

Figure 10.5.2 Moving Platforms Audio Loop GameObject Hierarchy Location and AudioSource Component

You will notice that the Play On Awake and Loop functions have been activated and that the Spatial Blend parameter is set to 3D.

The Rising Platform GameObjects and AudioSources will move up and down to their preset locations continually when Unity is in Play Mode.

The Floating Platform GameObjects placed along the acid river, however, appear to start on the right-hand side of the level and move towards the left before disappearing from view. The game has been designed so that it looks as if there is a never-ending supply of these platforms to jump across the river; however, this is not actually what is happening in Unity. The Game Designers have done something clever to make the platforms appear to be spawning endlessly in the game level.

If you highlight one of the Floating Platform GameObjects in the Hierarchy, then view this object in the Scene View while the level is running, you will notice that the same three platform GameObjects are being continually animated. The animation begins out of the player’s view on the right-hand side and ends just out of the player’s view on the left. When the platform reaches the leftmost end point of the animation, it will instantly move back to the starting location on the right-hand side, out of the player’s view. As clever as this is, you may be thinking ‘Okay, so what’s this got to do with the audio? If the AudioSource is a Child of the Platform Body GameObject and I’ve made sure that it’s set to Loop and Play On Awake, then surely the sound will continue playing and moving along with the platform?’

This is all true; however, because the platform will jump from the far left- to the far right-hand side, you need to ensure that you set your Min and Max Distance parameters on the AudioSources very carefully. You may want to reduce the Min and Max Distances to make sure that the player is not able to hear this looping sound suddenly panning from the left-hand side to the right-hand side when the animation restarts. It is important that the audio does not negatively draw attention to the Game Designer’s sleight of hand to create the player’s perception of an endless supply of platforms.

Videos games designers, much like magicians, have used tricks like this for years to create illusions for the player. They make it seem that the game is functioning in one way, but in reality, the mechanics behind the game may be doing something else. If this topic interests you, research how they managed to create a functioning mirror in Duke Nukem 3D (1996), something that games are only now able to do properly using the latest consoles and PC graphics cards.

Level end SFX

The following section will walk you through how to add in SFX for the gateway that appears at the end of Level01 to transition the player into Level02 and the final cutscene in Level02 featuring the spaceship flying down to collect Ellen at the end of Level02.

Level01 gateway

After defeating the Grenadier boss in Level01, a blue particle effect will appear and the player will find they are able to now walk through the doorway at the back of the raised platform and load into Level02.

Figure 10.6.1 Level Transition Gateway at End of Level01 after Grenadier Boss Has Been Defeated

There is currently no Audio Implementation in the Silent 3D GameKit Project, so unlike the previous mechanics, to add a Seamless Looping sound for this event, you will have to create and implement the AudioSource yourself.

As the AudioSource will need to be set to Loop for this mechanic, you will need to create a Looping Audio Asset.

Locate the TransitionStart GameObject in the Hierarchy; this will be found near the top of the Hierarchy

Create a new AudioSource as a Child of the TransitionStart GameObject

Add your Audio Asset to the AudioClip parameter

Set the AudioSource GameObject to be Enabled

Set the Play On Awake and Loop parameters on the AudioSource to be Enabled/Activated

Set the AudioSource Spatial Blend and Min/Max Distance settings you think are appropriate

Playtest the game and to check that your AudioSource is mixed as expected and Enabled at the correct point in the game

Figure 10.6.2 Hierarchy Location to Add in AudioSource GameObject as Child of TransitionStart GameObject

You will notice in the Hierarchy that the Transition Start GameObject is Disabled when starting the level. You must set your AudioSource Child GameObject to be Enabled when starting the level. Using Play On Awake will ensure that when the Transition Start GameObject gets switched on/ Enabled after the Grenadier enemy is defeated, your AudioSource will begin playing when required at the correct time.

You will explore how this Transition Start GameObject becomes Enabled after defeating the Grenadier enemy, when further exploring the existing implementation for the Grenadier enemy in relation to interactive music in the next chapter.

Level02 spaceship cutscene

After defeating the two Grenadiers at the end of Level02 and walking through the door at the end of the level, an animation is triggered where the spaceship shown at the start of Level01 flies down into the level. When Ellen walks close to the ship, the loading screen starts and the player is returned to the Start – Front End Scene.

The following steps will allow you to add in a looping audio asset for the ship SFX for this animation. A looping sound is required because after the ship has landed, the player could choose to wait as long as they wanted before then walking up to the ship to end the level. As the player could choose to stand within the final room in Level02 as long as they want, we need to ensure the sound we create for this will loop. You may be initially be thinking that ‘just a single looping sound won’t be enough for the spaceship to have a really cool sounding arrival sound at the beginning of the cutscene’, and you would be right. We will return to this mechanic in Chapter 13 after covering a few more required skills to then also add in a separate, more detailed One Shot spaceship arriving sound that will play before this looping sound.

Figure 10.6.3 Spaceship that Appears at the End of Level02

As the AudioSource will need to be set to Loop for this mechanic, you will need to create a Looping Audio Asset.

Locate the Dropship GameObject in the Hierarchy in Level02

Create a new AudioSource as a Child of the Dropship GameObject

Ensure the Transform parameters for Rotation and Position are set to 0

Add your Audio Asset to the AudioClip parameter

Set the AudioSource GameObject to be Enabled

Set the Play On Awake and Loop parameters on the AudioSource to be Enabled/Activated

Set the AudioSource Spatial Blend and Min/Max Distance settings you think are appropriate

Playtest the game and to check that your AudioSource is mixed as expected and Enabled at the correct point in the game

Figure 10.6.4 Hierarchy Location to Add in AudioSource GameObject as Child of Dropship GameObject

You will notice in the Hierarchy, that the Dropship GameObject is Disabled when starting the level.

You must set your AudioSource Child GameObject to be Enabled when starting the level.

Using Play On Awake will ensure that when the Dropship GameObject gets activated after entering the final room using a Trigger Area; your AudioSource will begin playing when required at the correct time and from the correct spatial location in the gameworld.

5 quick tips

You can temporarily Disable the Parent Enemies GameObject in the Hierarchy; this will allow you to progress through the level much faster and with fewer interruptions when working on the other mechanics in the game. Remember to Enable them again when you are finished!

For mechanics that use an identical setup but are not using Prefabs, such as the moving platforms, you can copy/paste the settings from one AudioSource or RandomAudioPlayer Component to the others.

Make sure you note down if the game mechanic requires a One Shot or a Looping Audio Asset before designing the sound.

If you are not sure why you cannot hear a sound you had added to an existing mechanic, try temporarily setting the AudioSource to 2D. This will quickly show you if the sound is not implemented correctly or if it is just that the 3D Min/Max Distance parameters are not set correctly.

Now that we have covered the majority of the game mechanics within the level, if you wish to implement your own dialogue and subtitles, you can integrate the Dialogue InfoZone GameObjects into the various Pressure Pads, Crystals etc.

Tip

To see an example of how to Enable or Disable the subtitles and dialogue AudioSources as covered in the previous chapter, look at how the LVL01_InfoZone05 GameObject has been assigned into the InteractOnTrigger script in Level01 on the SwitchCrystal2 Parent GameObject found using the following Hierarchy path:

Level01Gameplay > Crystals > SwitchCrystal2

Chapter 10 practical tasks

The practical task for this chapter is to make and implement your own SFX for the game mechanics explained within the chapter.

Adding SFX for Destructible Boxes

Adding SFX for Health Chests

Adding SFX for Collect Staff Weapon

Adding SFX for Door Pressure Pads and Opening Cutscenes

Adding SFX for Crystals

Adding SFX for Moving Platforms

Adding SFX for Gateway between Level01 and 02

Adding in SFX for the Spaceship at the end of Level02

The majority of the mechanics covered in this and the previous chapter use screenshots and explain these in the context of the Level01 Scene. Any mechanics that are currently using Prefabs will automatically have the audio added to them across both levels if you used the Overrides option on the Parent GameObject for the Prefab.

As you will notice, not all mechanics currently use Prefabs, such as the Crystals or Pressure Pads to trigger the door opening animations. This is because they have been configured individually in the Inspector or there is only one use of that mechanic in the whole game.

If a GameObject is not a Prefab then in this case, you will have to add in the AudioClips and AudioSource mix changes individually to every GameObject for that mechanic in the game.

11 Interactive music

DOI: 10.4324/9781003055167-11

This chapter will cover several different techniques and methods to create, edit, and implement interactive music inside the 3D GameKit. It will explain various approaches you can take to implement your own music in the game and provide analysis and examples of interactive music used in many games you are no doubt already familiar with.

Interactive music is practically considered a requirement in professional video games; the majority of modern video games will feature some kind of dynamic music systems that use adaptive or interactive music in a variety of ways. This chapter will cover several different methods of integrating adaptive and interactive music. It is your choice which of these techniques you want to use in your 3D GameKit Project (or if you wish to use a unique method of your own creation).

The music for a video game can be either composed specifically for the game or an existing song by a composer or band/artist. The Grand Theft Auto, Tony Hawk’s Pro Skater, and Singstar games series are well known for making use of a large number of popular existing songs. This is known as licensed music. This is music that has been created previously by an artist or band, and the game publisher must obtain the rights to use this music in their video game. On AAA games, a Music Supervisor will coordinate the licensing process by obtaining (and paying for) the relevant rights to the piece of music. Not correctly licensing the music for a game can leave the Games Developer (and potentially you, if you work on the audio for the project) open to lawsuits.

Interactive music implementation overview

At a minimum, interactive/adaptive music is defined as music that will change in some way, depending upon some action the player has taken or change within the game.

Dynamically changing music in video games generally falls under one of these two categories, Interactive or Adaptive.

Interactive music is a musical change that happens because of player input.

Adaptive music is a musical change that is driven by a change within the gameworld.

Space Invaders, originally released in 1978, featured one of the first major developments in Game Audio. It introduced adaptive non-diegetic music during gameplay. This was an important milestone in the development of Game Audio, as it was also the first ever instance of dynamically changing music in video games.

The music in this game features a four-note looping ostinato or riff; the tempo of the music increases as the enemy spaceships come closer to the bottom of the screen. When this happens, the game will end in a loss; this requires the player to destroy the enemy ships with increasing urgency. This simple technique manipulates the gamer’s emotional response and raises the pressure of failure as the enemy ships get closer to the screen resulting in failure.

Non-diegetic music (underscore)

The most common form of music in video games is non-diegetic music. This refers to music that does not come from a particular location with the gameworld. It is often used to enhance or help guide the emotions that the player should be feeling; this is commonly known as an underscore. Underscores are often written to work on a subconscious level, bringing story elements together in its use of themes and motifs, as well as to intensifying the emotional context of a scene. It also may inform the player or viewer of something that might be off-screen, such as the shark in Jaws (1975). Extra-diegetic or non-diegetic music also helps with setting the stage by implying a specific time in history or a place in the world. With extra-diegetic music, the viewer does not expect to see the instruments on the screen playing the music, i.e. the music would be heard by the person playing the game but not necessarily by the playable character in the gameworld at that moment in time.

It is commonly observed that some of the best film and video game musical scores are not always actively noticed by the audience or viewer during the viewing/playing experience. Overuse of more obvious musical scores can take the viewer out of the experience by bringing what should be an unconscious element to the forefront for the listener, competing with rather than reinforcing the visuals.

Diegetic music (source music)

Diegetic music is music that the playable character would hear in the gameworld itself. In films, this is usually referred to as source music. In a movie, TV show, or game, if you see someone on screen playing a guitar, you expect to hear the guitar. One of the main reasons for choosing to make use of diegetic music is to enhance the player’s experience and to increase the realism of the gameworld.

In Bioshock Infinite Burial at Sea DLC (2013), when playing as Elizabeth in Paris, the level begins with the player looking at and then listening to an old record player. As you progress through the level, there are moments when you can choose to walk up to various NPC musical ensembles. These characters include a barbershop quartet, people whistling, and an accordion player. When you see the barbershop quartet on screen, the additional musical elements have been mixed so that you can hear them singing along with, and adding to, the background music track coming from the record player. This is an excellent example of combining diegetic music from the NPC musicians with non-diegetic background music that feels totally natural when playing the game.

Another example is from Mass Effect 3 (2012). When the playable character is standing outside a nightclub, they hear the music with EQ processing added to make it appear as if the music is emanating from inside. This is music that the playable character would also be hearing as part of the gameworld.

Games like Grand Theft Auto V (2013) and L.A. Noire (2011) are 3D simulations of semi-realistic worlds. Both games include a driving mechanic where players travel around the map between missions. These vehicles have radios and the player can select between the radio stations, so the music changes according to the player’s radio channel selection as they’re driving through the gameworld. This is another example of diegetic music.

One final example of diegetic music in video games occurs at the beginning of Assassin’s Creed III (2012), when the playable character is tasked with infiltrating a theatre while an opera is being performed, to assassinate a target. You can see the actors and musicians; the music is diegetically coming from the gameworld and can be heard by both the person playing the game and by the playable character and NPCs.

While playing a game, if you see a jukebox, or some other music-making device or musician on screen, then you will naturally want to hear the music that it creates. The realism or immersion of the gameworld would be broken or at least reduced if you were unable to interact with the object or game character and hear some diegetic music. Both Composers and Sound Designers need to be wary of destroying the illusion of a gameworld for the player.

In all of the previous examples, the diegetic music placement in the speakers is also very important to correctly simulate where the music is emanating from in an acoustic space. To achieve this, you will need to make full use of AudioSources set to 3D Spatialisation, the real-time panning in Unity, equalisation, and reverb to simulate this within the gameworld.

Occasionally, the distinction between diegetic music and extra-diegetic music can become blurred. For example, you might start off listening to diegetic music, but then as the story progresses, the same theme can be heard non-diegetically, reinforcing emotional elements of the storyline. A perfect example of this is later in the Bioshock Infinite Burial at Sea DLC (2013) level, as the diegetic music shifts and modulates from a major to a minor key and slowly transforms from a piece that is relaxing and diegetic to non-diegetic and terrifying.

Music-as-gameplay

The third category of music in video games is music-as-gameplay. This is when the player generates the music in real time as they play the game.

Technically, all interactive music in video games could be considered music-as-gameplay, as the majority of interactive music systems will have a somewhat direct relationship between the musical composition and the player’s actions. For example, when a player makes choices such as emerging from cover and entering combat, this triggers certain music to be played. The music in the game may change from a relaxing music composition to a composition with different instrumentation, or a faster tempo to communicate danger or a potential threat. Games such Skyrim (2011), Uncharted 4 (2016), or RTS games such as Zeus: Master of Olympus (2000), however, are not categorised as featuring music-as-gameplay as defined in this book.

One of the defining characteristics of this type of interactive or adaptive music system is that the game engine is creating the music as an immediate, direct reaction to the actions of the player.

Games such as Rock Band (2007) and Guitar Hero (2005) recreate the effect of performing in an actual band; the player will press a button on a controller to simulate playing a real instrument, and this will instantly trigger a percussive sound in musical rhythm or cause a melodic sequence of notes to play.

These games typically use licensed music from popular bands and artists, and quite often the music in these games is played back depending on how well the player performs in the game. The better the player performs, the closer to the original licensed song the result will be. The dynamic music system creates or changes the music in a much higher level of detail than a broad change in the music, such as entering combat in a role-playing game and hearing combat music replace the ambient music.

Other games that fall under this same banner are Dance Dance Revolution (1998), Singstar (2017), and the VR game Beat Sabre (2018). Even though in these cases the music playback will not change, players listen to the rhythm of the music and increase their score/points depending upon how accurately they are able to synchronise their actions by either dancing, singing, or swinging their arms in VR in time with the music.

Player-generated music

In some games, the player creates music dynamically while playing the game without requiring any musical talent or knowledge. Examples of this include the FPS/rhythm action game Rez (2001). In this game, the player creates music dynamically by shooting down geometric shapes in rhythm with the music, in effect sequencing and triggering musical notes and patterns in the game.

In Detroit: Become Human (2018), the player can choose if they wish to play a piano in the game and decide what style of music to play based upon their/the playable character’s mood. How accurately they time their button presses with the prompts on screen will determine how well the character performs the piece.

The interactive music in Sea of Thieves (2017) contains quite a sophisticated player-driven diegetic music element that is able to let other players join in whenever they want and ‘jam’ together, providing an additional harmony layer to the instrumentation. If the ‘lead’ instrument or player were to stop playing, the lead melody element would be taken over by a remaining player in a very smooth and dynamic way. The interactive element of this musical performance by the playable characters can even take into account if they are currently drunk in the game. The ‘drunken’ character will still join in with the jam session, but will not play perfectly in time with the sober members of the band and will occasionally play notes out of tune or time.

Other uses of interactive/adaptive music in notable video games

Aside from manipulating the player’s emotional responses as an underscore or being used as a primary gameplay mechanic, music can also be used to subtly guide the player. Many games showcase the practice of reinforcing positive player actions through music, to give the player aural clues to help them solve a puzzle.

Within Portal 2 (2011), interactive music was used in a number of ways, such as in certain puzzles where the player had to direct a laser beam using a redirection cube. The music subtly changes to indicate to the player that they have successfully solved a stage of the puzzle. If they were to make a ‘wrong move’, the harmonic tones within the music would change to indicate to the player that this action in the game is taking them further away from correctly solving the puzzle.

In L.A. Noire (2011), the player acts as a detective solving crimes; when they arrive at a crime scene, they then explore the area looking for clues. The developers were able to provide information subtly to the player through music; they faded down the music volume when the player strayed too far. This was an unobtrusive way of letting the player know there were no clues in their current location, and that they should turn around and head back towards the main crime scene area. The end result of this creative use of music was, in my professional opinion, a much more effective and immersive solution than adding in ‘invisible walls’ or Solid Collision to keep the player within the area.

The creative use of adaptive audio effects can also help to make the music mix react to what is going on within the game; Wipeout HD (2008) features a great example of this. When the player activates a shield power up that surrounds their ship, protecting it from hazards in the gameworld, a Low-Pass EQ Filter is applied to the music. This interactive mix change makes it sound as if the music itself is having its high frequency content attenuated as it passes through the ship’s shield power-up.

Many games feature the use of different music compositions transitioning between one other at different points in the game. The Mario Kart series from Mario Kart 64 (1996) to Mario Kart 8 Deluxe (2017) does this very effectively. In Mario Kart, there are usually between three and four music compositions the player will hear corresponding to the different major sections from the level. As the player progresses from one section into another, the musical tracks switch. I would assume that some form of Trigger Areas have been implemented to perform this musical change. What makes the dynamic song transitions so effective is that, no matter how fast or slow a player drives around the track, the music will always change when crossing these Trigger Areas. A player who is leading for the majority of the race will experience these musical transitions between sections happening more frequently than a person who is lagging behind in last place. In addition to this, typically the tempo of the music for all sections will increase when the player begins the final lap. This increase in tempo helps to urge the player on and make the final lap feel much more exciting than if the same static music track played from the start to end of the race.

Music systems, like all other areas in gaming, have grown increasingly complex and been put to new and creative uses with every subsequent release. Nintendo in particular has continually been leading the frontier to improve the integration of music within gameplay to enhance the fun elements of their games.

In the early 1990s, LucasArts game developers pioneered the Interactive Music Streaming Engine (iMUSE), which was capable of dynamically switching the instrumentation of the music. This was put to great effect in Monkey Island 2: LeChuck’s Revenge (1991). In the Woodtick area of the game, a variation of the music theme featuring different instruments is played as the playable character enters or exits the various buildings, accompanied with a short musical transition piece.

The New Super Mario Bros game by Nintendo (2006) builds upon this idea of changing the instrumentation in a much more fluid way when in the overworld hub area. The instrumentation is able to change and react much faster compared with the LucasArts iMUSE system.

Nintendo again improved upon, and by all accounts set a new standard at the time of writing for, creative use of musical implementation in Super Mario Odyssey (2017). They did this by adjusting the pitch of all of the sound effects within the game to be in tune with the current background music track. The end result of this was that the playful nature of the overall audio experience was dramatically enhanced.

Dynamic, interactive, and adaptive music within video games has come a long way from the first instance in 1978 with Space Invaders. A brilliant example of this is Tetris, originally released in 1984. The re-imagining/sequel game Tetris Effect, released in 2018, demonstrates just how far interactive, adaptive, and dynamic music systems have come, featuring a modern musical accompaniment far exceeding the interactive music capabilities utilised in the original game.

Editing seamless music loops featuring Reverb

When creating seamless music loops for use in a dynamic, interactive, and adaptive music system, there are a number of techniques you can use that build upon the Top and Tail looping technique for sounds, as covered in the Chapter 3 Seamless Loops section of this book.

To quickly recap, the Top and Tail technique is used to create a seamless loop for sound effects. It involves splitting the audio file and moving the front part of the sound to the end, joining the two sections with a crossfade. This helps ensure that when the sound is set to loop and returns to the beginning from the end, the Loop Transition Point is not noticed by the player.

This technique is not always suitable for music, as the musical sections of a song or composition need to harmonically resolve, and the edit needs to work for the piece in a much more precise way than, for example, a background ambience SFX layer. The main issue you will encounter is attempting to simply loop the piece of music. When listening to the music looping back from the end to beginning, it almost sounds like the energy in the piece of music is reduced at the Loop Point.

Open your favourite DAW and import the Example 1 Music Loop Before Edit Audio File from the Chapter 11 downloadable resources folder and set your DAW to 85 BPM. Next, either duplicate the music track or select the audio and create a Loop Point by selecting the entire length of the audio file. Listen to the Loop Point yourself and observe the subtle but noticeable drop in energy within the piece as it plays from the end of the audio file back to the beginning.

The main reason that the music feels like it has dropped in intensity, or lost some energy when attempting to loop the music audio file, is simply because it has. When returning from the end back to the beginning of the loop, the noticeable drop in energy is because the reverb from the end piece of music is not present right at the beginning of the music file.

Next are three variations on this Top and Tail technique that can solve this issue involving the use of reverb. The variations on this technique can be applied if you are mixing the piece of music in its entity from scratch, or if the music already exists as a stereo master and you need to edit this into a seamless loop with no drop in intensity or energy at the Loop Point.

Editing and mixing multitrack music

If you have composed a piece of music you intend to use within a game, or even are mixing the multitracks from scratch, the following technique will enable you to maintain the energy from the end point of the loop back to the beginning.

This book does not cover the specific art of composing or mixing music. If this is something you are already familiar with, then mix the piece of music as you normally would. As with most mixes, there is a high probability you will have used reverb within your mix to create depth with the various instruments. If you have not chosen to do this, then consider revisiting your mix and, for the purposes of learning this technique, add some reverb.

Ensure that when editing and arranging your music, the start and end points naturally flow from one into another; attempt to maintain the same instrumentation and intensity within each instrument and the overall mix from the end section and the start section of the arrangement

Next, copy the first four bars of music from the instrumentation for all instruments and paste this at the end of the arrangement

Figure 11.2.1 REAPER Project Featuring Looping Musical Arrangement

Render/export or record your entire musical edit down to a stereo audio file

Re-import this into your existing project or create a new project/session in your DAW

As you can see in Figure 11.2.2, I have imported this into my original DAW project/session and lined the audio file up to correspond with the existing markers. These relate to the various sections of the musical arrangement in the topmost track.

Figure 11.2.2 Music Arrangement Re-imported as Stereo File in REAPER Project

Next, split the audio file at the original end of the arrangement or Loop Point

Trim and remove everything past the Loop Point except the last half beat of music

Take this small piece of music immediately after the Loop Point and move it to the very beginning of the main music audio file on a new track

Finally, apply a very small fade in over a few samples on the main music track at the start and the end

Figure 11.2.3 Editing Original Stereo Musical Arrangement and Placing Small Section on New Track at Start of Arrangement with Fade Out

Download and compare the Example Music Loop Before Edit version of the musical arrangement, listening to this loop and the Example Music Loop After Edit version in your DAW or media player set to Loop. Specifically listen for the difference in energy or intensity as the music loops from the end section back to the beginning.

Unfortunately, I am unable to share the REAPER Project in the downloadable resources due to specific copyright laws restricting access to the individual portions of the song. However, there are many stores/resources on the internet where you can download small sample packs of audio to practice creating your own music arrangements and edits as shown in these previous steps.

The individual audio files to recreate your own similar arrangement can (at the time of writing) be downloaded for free from www.bigfishaudio.com.

This particular piece used in Example 1 can be found in the ‘Free Loops’ section within the ‘Free Sample Pack – Country’ and is in the ‘Country Pop’ sub-folder.

Alternatively, there are many stores/resources on the internet where you can download small sample packs of audio to practice creating your own music arrangements and edits as shown in these previous steps. Try searching for ‘music loops multitrack’ to find a number of options. Please do take the time to read through the specific terms and conditions before you download any files; specifically, make sure that it states the music files and your own arrangements can be used in an ‘academic or non-commercial use’, i.e. your personal 3D GameKit Project.

Editing music with a natural Reverb tail

In this scenario, you have a piece of music that has been edited and mixed down to a stereo master. For example, you have several bars of music that feature multiple instruments and end in a natural final note or percussive sound with the naturally decaying reverb. You can obviously still edit the arrangement of the music but will have considerably less creative freedom than if you had access to the entire multitrack with a single instrument per audio file (as in the previous example if you downloaded the multitrack audio files and created your own arrangement). This example uses the stereo mixdown of the completed arrangement from the same www.bigfishaudio.com ‘Country Pop’ sub-folder.

Download and compare the Example 2 Music Before Edit version of the musical arrangement, listening to this loop and the Example 2 Music After Edit version in your DAW or media player set to Loop.

Begin by importing the Technique 2 Original Music file into your DAW and set the BPM to 85

Remove/trim the first five bars of music so the composition now starts with the Verse section

Find the beat where the music stops and the tail of the final notes begins

Split the Audio file at this location; this will become your Loop Point

Figure 11.2.4 Splitting Audio File Containing Musical Arrangement at Loop Point

Move the audio past the Loop Edit Point to a new Track at the beginning of the arrangement

Edit the length of this to make it shorter and apply a Fade Out if required

Apply a Fade In over a few samples on the main audio track and the smaller tail section

Figure 11.2.5 Editing Original Stereo Musical Arrangement and Placing Small Section on New Track at Start of Arrangement with Fade Out

Listen to the audio as it loops from the end of the arrangement back to the beginning. It should not sound like it has lost any energy. If you listen to the arrangement starting from the beginning, it may sound slightly strange as you are listening to the beginning section and the end section together. Do not worry about this at this moment; it is easily solved in Unity when you implement your music in the game by fading in the music when it begins to play. How to do this is discussed in a later section of this chapter.

Editing music without a Reverb tail

In this scenario you have a piece of music, say eight bars long, without a natural end reverb tail as described in the previous example. You can follow these simple steps to artificially create the reverb tail yourself, and then edit this using the previous technique. The following example also uses another free composition from www.bigfishaudio.com.

This particular stereo mixdown used in Example 3 can be found in the ‘Free Loops’ section within the ‘Free Sample Pack – Electro Pop’ and is in the ‘Escape’ sub-folder.

Begin, as with all of the previous techniques, by adding the music audio file into your DAW and setting the Project/Session to the same BPM as the music track – 90 BPM

Trim/delete the first eight bars of music

Trim/delete the last eight bars of music, leaving only the middle/louder section of the original composition

Figure 11.2.6 Entire Musical Arrangement

Create an Auxiliary track and place a Reverb Plugin on this

Create an Additional Audio Track; duplicate your music audio file onto this and edit to so that only the last one bar of audio remains

Send/route the Additional Audio Track to the Auxiliary track with the Reverb Plugin

Figure 11.2.7 Duplicating Last Bar of Music, Adding to New Track, and Routing to Auxiliary Reverb Track

Now, Solo the Reverb Auxiliary and the Additional Audio Track with the small piece of music just before the Loop Point

Attempt to use your reverb to match as closely as possible the reverb within the original mix, in particular play the audio segment, and listen to the reverb after the playhead has passed the Loop Point

If you struggle to hear the reverb to match this appropriately, then try using a ‘Short Plate’ type preset

Next, record just the output of Reverb Auxiliary to another new Audio Track to ‘print’ or record just the reverb applied to the end section of music by routing the output of this to a new Audio Track in your DAW

Figure 11.2.8 Created Render of Last Bar of Music with just Reverb and Re-Importing

For reference, the topmost track is the main music arrangement, the middle track is the final bar of the Additional Audio Track, and the ‘printed’ or recorded reverb is the bottom track.

You can see the reverb tail section after the Loop Point; this begins where the original music ends, just after the cursor on bar 49 in the example in Figure 11.2.8.

Mute the Additional Audio Track

Edit and split this newly recorded reverb audio at the Loop Point

Move the portion of the newly recorded and edited reverb audio after the Loop Point to a new track at the beginning of the arrangement

Edit the length of this newly recorded reverb tail you have just created and moved to the beginning of the arrangement to make it shorter and apply a Fade Out if required

Apply a Fade In over a few samples on the Main audio track and the smaller tail section

Figure 11.2.9 Editing Reverb Audio File at Loop Point, Moving to Beginning of Arrangement, and Adding Fade Out

At this point, you have effectively created a ‘fake’ reverb tail and edited this as described in the previous technique. At this point, listen to the arrangement as it loops from the end of the arrangement back to the beginning. It should sound much smoother and more natural because the reverb is effectively ‘carrying through’. Much like the previous example, if you play the loop from the beginning, don’t worry if this sounds a little strange as you will explore in the next section how to apply a Fade In, inside Unity on the AudioSource. This will in effect mask this slightly strange start of the file, as the volume can be set to Fade In slowly, thus hiding this slightly abrupt start from the player.

Implementing your own dynamic music system in the 3D GameKit

At this point in the project, if you want to write your own unique music but are not a composer, that’s totally fine. There are a number of additional resources where you can download music to use within your project. If you like the original music used with the 3D GameKit, you can import the original music tracks from the With Audio version of the project into your own Silent project.

The existing music audio files can be found in the following path within the Project Panel Assets folder:

Assets > 3DGameKit > Audio > Music

There are two different methods in this book that will demonstrate how to add interactive and adaptive music to your 3D GameKit Project. Both methods are explained independently of one another for increased flexibility; however, they can be used in conjunction with one another. You are free to choose the interactive method, the adaptive method, or a unique idea of your own.

The interactive music method allows you to have one track of music constantly playing and enables you to add additional AudioSources and Collider GameObjects. This allows you to fade between different music tracks when Ellen is standing in specific areas of the level.

The adaptive music method will walk through the steps to implement an adaptive music change to switch between an ‘ambient’ piece of music and a ‘combat’ piece of music when fighting the Grenadier boss enemy at the end of Level01.

Both the interactive and adaptive music methods will need to be set up individually for Level01 and Level02.

The descriptions in this chapter will refer to the Level01 Scene file but can also be easily adapted and integrated within the Level02 Scene file following the same set of steps.

Interactive music method

This method of music implementation will involve adding in a number of Trigger Areas to the level to fade the volume between various AudioSources depending upon where the playable character is standing in the level.

The Script Components in the With Audio project have been coded to use one primary or main piece of music, and then to fade this primary piece of music out and fade in your other secondary audio tracks when the playable character is within the specific Trigger Areas you have added to the level. If Ellen leaves the Trigger Area, the secondary music will automatically fade out and the primary music will fade back in.

This method is very useful if, for example, you want to have different pieces of music that represent the various sections of the levels. It is important to ensure when using this method that your various musical tracks are composed in a complementary musical key and will sound appropriate as they fade between the various music Audio Assets.

Start by creating a New Empty GameObject and name it Interactive Music

Add in the InteractiveMusicController script Component to the Interactive Music GameObject

Figure 11.3.1 Interactive Music Controller Script Component Added to New GameObject

This InteractiveMusicController script has a number of parameters and variables.

The Audio Source Max Volume parameter is the volume your AudioSource will play back at when at full volume. This parameter will directly affect and control/overwrite the Volume parameter of all of your music AudioSources.

Start Volume is the volume the AudioSource will be set to when beginning the level. I would advise leaving this at the default value of 0, as you do not want to immediately blast the player with a sudden burst of music at the start of the level. It is a much better idea to adjust the Volume Fade Time parameter to gently fade up the volume of the music as soon as the level begins. This Volume Fade Time parameter is how long the AudioSource will take to reach the Audio Source Max Volume value from its current value. This value should be customised to match the tempo of the music track you choose. A music track with a faster tempo will typically require a shorter Fade Time; a slower tempo track likewise will typically require a longer Fade Time.

The Play On Start checkbox sets if the music should begin playing at the start of the level; you want to make sure this Play On Start function is Enabled. If you want to start the music at a later point in the level, consider activating the Interactive Music GameObject containing the InteractiveMusicController using another script or event. This could be accomplished, for example, by using the InteractOnTrigger script to create a Trigger Area, or linking this into an already existing game mechanic such as collecting the staff weapon and this action/event then Enabling the Interactive Music GameObject.

Using this method, you cannot control the volume of the music AudioSource GameObjects directly on the AudioSource Component using the Volume parameter. This InteractiveMusicController script will dynamically adjust the volume of each assigned music AudioSource to perform the volume fade in and fade out. Balancing the individual levels of each AudioSource or piece of music can be achieved using the Unity Audio Mixer as explained in the next chapter.

The Audio Sources dropdown variable initially contains a Size parameter; this will add in the number of AudioSource variable drop targets corresponding to the value entered. It is up to you how many of these you need. In the next example, I have entered four as used in the original music implementation within the game found within the Level01Music GameObject in Level01.

The AudioSource you add first in the list to the Element 0 Variable will be the primary music track, as discussed earlier in this section of the book. When the playable character is within the Trigger Areas over the amount of time in seconds as specified in the Volume Fade Time Variable, the subsequent AudioSources in the Elements 1–3 Variables will Fade Out this Primary Music AudioSource. It will simultaneously Fade Up the volume of the secondary music track over this same Volume Fade Time Variable value. This in effect will perform a smooth volume crossfade if the Volume Fade Time is set to an appropriate value for the tempo of the audio tracks.

Next, create a new AudioSource GameObject for the main/primary music track

Name this Primary Music AudioSource

Add your looping music AudioClip, set the volume, and activate the Loop parameter on the AudioSource

Ensure the Play On Awake parameter of the AudioSource is Disabled

If you do not want the music to be affected by the Reverb Zones within the level, either set the Reverb Zone Mix parameter to 0 or Enable the Bypass Reverb Zones checkbox on the AudioSource

Set the Priority parameter on the AudioSource to a High priority value

Finally, set your 2D or 3D spatialisation settings as required

In all example steps I will choose to use 2D Spatial Blend as used in the With Audio version of the game, but you are free to implement diegetic or non-diegetic music in your project however you like.

Figure 11.3.2 Creating New AudioSource GameObject and Setting to Bypass Reverb Zones and Loop

Next, create as many secondary music AudioSource GameObjects as you need and use the same AudioSource settings/guidelines as described in the previous step

Finally, assign your AudioSource GameObjects to the AudioSources Variable Elements on the Interactive Music Script

Remember to assign your Primary Music AudioSource to the top Element 0 Variable

Figure 11.3.3 Creating Adding Secondary AudioSource GameObjects and Assigning to InteractiveMusicController Script

Select the first of your Secondary Music AudioSource GameObjects in the Hierarchy and add in whatever shape of Collider best fits your needs using the Add Components button in the Inspector (in the next example, I will choose a Sphere Collider)

Set the GameObject Layer to Collider, as with any other Trigger Area described in this book

Set the Collider Is Trigger checkbox parameter to be activated

Move your Secondary Music AudioSource GameObject containing the Collider where you need it in the game level. You can resize the Collider to fit within the space you place it

Use the Add Component button in the Inspector to add in a SecondaryInteractiveMusic script

Set the Layers dropdown parameter option to Player like with any Trigger Area examples covered so far

Figure 11.3.4 Adding Secondary Interactive Music Script and Sphere Collider Components

If you have additional secondary music AudioSources, then repeat all the previous steps, adding in a Collider and SecondaryInteractiveMusic script and repositioning the GameObject where required in the level. Please follow all steps relating to parameter settings carefully to ensure your interactive music system will work without issues.

You can add in as many secondary music GameObjects as you want, as long as the Colliders DO NOT touch one another.

As described with Trigger Areas in previous chapters, if the playable character is able to stand in several Trigger Area colliders at once, the InteractiveMusicController script will not know what value to set the volume of the AudioSources to. This is likely to result in audible sound issues.

You may also notice in the With Audio project that when playing through Level01, the background ambient music does not fade into other pieces of music but instead seems to become silent. In the With Audio music implementation, ambient SFX have been added to the Secondary Music AudioSources AudioClip parameters instead of additional pieces of music. This has the effect of the background music swelling in and out at various points in the level. Consider also using this technique, or building upon it, and using a silent audio file if you would like to fade the Primary Music AudioSource out completely when the playable character is standing in certain locations within the gameworld. The reason this particular technique can be used is that it is not always necessary to have music playing at all times within a game level, and by introducing sections with no music, this can keep the player more engaged than if the music plays continuously the whole way through.

Adaptive ambient/combat music switching method

This method will allow you to switch off or mute your existing ‘ambient’ music AudioSources and trigger an entirely different piece of ‘combat’ music during the Boss Fight with the Grenadier enemy. After defeating this enemy, the combat music will stop playing and the ambient music will then begin playing again. The instructions for this method assume you have chosen not to use the interactive music method as outlined previously. Should you wish to combine both interactive and adaptive methods, additional instructions will be provided where required.

Start by creating a new AudioSource GameObject for the ambient music track

Ensure this GameObject will be Enabled by default (unless you wish to use a Trigger Area or a previously covered game mechanic to Enable the ambient music AudioSource GameObject at some point in the level)

Rename this AudioSource GameObject Ambient Music AudioSource

Add your looping ambient music AudioClip and activate the Loop parameter on the AudioSource

Ensure the Play On Awake parameter of the AudioSource is Enabled

If you do not want the music to be affected by the Reverb Zones within the level, either set the Reverb Zone Mix parameter to 0 or Enable the Bypass Reverb Zones checkbox on the AudioSource

Set the Priority parameter on the AudioSource to a High priority value

Finally, set your 2D or 3D Spatial Blend settings as required

At this point, if you play the game, you should be able to hear your background music. However, it may seem like it starts abruptly at the volume specified on the AudioSource Volume parameter.

Create another new Empty Child GameObject

Rename this Empty GameObject Fade In Ambient Music

Ensure this GameObject will be Enabled by default

Select the Ambient Music AudioSource GameObject in the Hierarchy and use the Inspector to add in the AudioSourceFadeInVolume Script

Assign the Ambient Music AudioSource to the Audio Source variable by dragging and dropping it from the Hierarchy into the variable drop target zone

Figure 11.3.5 Adding AudioSourceFadeInVolume Script to Ambient Music AudioSource GameObject

This AudioSourceFadeInVolume script has four variables. When the Fade In Ambient GameObject is Enabled (either by default when starting the game or via another game mechanic), it will reset the volume of the AudioSource attached to the Audio Source variable to 0. It will then increase/fade up the Volume parameter on the Audio Source variable to the Target Audio Volume, over the number of seconds entered into the Fade In Time Seconds variable.

The code within this script means that the Volume parameter directly on the AudioSource will have no effect, as this value will be overwritten and eventually replaced by the Target Audio Volume value variable when the script has finished, increasing the volume from 0 to a maximum value of 1 as specified on the Target Audio Volume variable.

Much like the previous example using the InteractiveMusicController, the Fade In Time needs to be set to an appropriate value for the tempo of the music. The faster the tempo, the quicker fade time is likely to be required. The slower the tempo, the longer the fade time is likely to be required to have a ‘musical’ sounding fade in.

After creating your Ambient Music AudioSource and adding the AudioSourceFadeInVolume, follow the next steps.

Create an AudioSource GameObject as a Child of the Grenadier Activator GameObject.

Hierarchy path is as follows:

(Level01 Scene) > Enemies > Grenadier Activator

(Level02 Scene) > Enemies > Grenadier Activator

Rename this AudioSource GameObject Combat Music AudioSource

Ensure this GameObject will be Disabled by default (presumably you don’t want to hear the combat music at the start of the game playing alongside the ambient music)

Add your looping combat music AudioClip and activate the Loop parameter on the AudioSource

Ensure the Play On Awake parameter of the AudioSource is Enabled

If you do not want the music to be affected by the Reverb Zones within the level, either set the Reverb Zone Mix parameter to 0 or Enable the Bypass Reverb Zones checkbox on the AudioSource

Finally, set your 2D or 3D Spatial Blend settings as required

Figure 11.3.6 Creating AudioSource, Assigning AudioClip and Bypass Listener Effects, Bypass Reverb Zones, Play On Awake, and Loop Parameters

The following steps will guide you through how to Disable the Ambient Music AudioSource GameObject and Enable the Combat Music AudioSource GameObject when you see the Grenadier enemies in both levels.

Select the GrenadierActivator GameObject in the Hierarchy and create a new Empty Child GameObject

Rename this Empty GameObject Mute Ambient Music

Ensure this GameObject will be Disabled by default

Add the MuteAudioSource script Component to the Mute Ambient Music GameObject

Assign the Ambient Music AudioSource to the Mute AudioSource Variable by dragging and dropping it from the Hierarchy into the variable drop target area

Figure 11.3.7 Creating Mute Ambient Music GameObject, Adding MuteAudioSource Script Component, and Assigning Ambient Music AudioSource to Variable

The MuteAudioSource script only has a single variable and a single function. It will mute the AudioSource assigned to this variable when the GameObject the script Component is added to becomes Enabled. In this case, it is used to mute the Ambient Music AudioSource when the Grenadier enemy appears on screen.

Should you have more than one Ambient Music AudioSource in your music implementation or if you are using the Interactive Music method outlined in the previous section, then, using the same Mute Ambient GameObject, add in as many Mute AudioSource scripts as you need to this single GameObject, before then assigning one Additional Ambient Music AudioSource to each Mute AudioSource script Component.

The Mute Ambient Music GameObject has been Disabled by default. This is because in the final series of steps, we will set the Mute Ambient Music GameObject to be Enabled when the Grenadier enemy appears on screen in Level01.

Next, you need to create an UnMute Ambient Music GameObject to unmute the ambient music when the Grenadier enemy/s have been defeated. This will allow the ambient music to be audible again.

Like the MuteAudioSource script, the UnMuteAudioSource also only has a single variable and a single function; it will unmute the AudioSource assigned to this variable when the GameObject the script Component is added to becomes Enabled. In this case, it is used to unmute the Ambient Music AudioSource when the Grenadier boss is defeated. Again, should you have multiple Ambient Music AudioSource GameObjects, then add in an UnMuteAudioSource Script for each AudioSource and assign to the variable.

The UnMute Ambient Music GameObject has also been Disabled by default. This is because, in the following series of steps, we will set the UnMute Ambient Music GameObject to be Enabled when the Grenadier enemy/s is defeated at the end of level. This will return the ambient music to the game and help reinforce to the player that the danger has passed.

Select the GrenadierDeadEvent GameObject in the Hierarchy and create another new Empty Child GameObject

Rename this Empty GameObject UnMute Ambient Music

Ensure this GameObject will be Disabled by default

Add the UnMuteAudioSource Script Component to the Mute Ambient Music GameObject

Assign the Ambient Music AudioSource to the UnMute AudioSource Variable by dragging and dropping it from the Hierarchy into the variable drop target area

Figure 11.3.8 Creating UnMute Ambient Music GameObject, Adding UnMuteAudioSource Script Component, and Assigning Ambient Music AudioSource to Variable

Next, you also need an additional Unmute GameObject to silence the Combat Music AudioSource when the Grenadier enemy has been defeated to ensure you will not hear both the Ambient Music and Combat Music AudioSources, playing over the top of one another.

Select the GrenadierDeadEvent GameObject in the Hierarchy and create another new Empty Child GameObject

Rename this Empty GameObject Mute Combat Music

Ensure this GameObject will be Disabled by default

Add the MuteAudioSource script Component to the UnMute Combat Music GameObject

Assign the Combat Music AudioSource to the Mute AudioSource Variable by dragging and dropping it from the Hierarchy into the variable drop target area

Figure 11.3.9 Creating Mute Combat Music GameObject, Adding MuteAudioSource Script Component, and Assigning Combat Music AudioSource to Variable

The final steps are to actually implement these GameObjects to Enable and Disable as required when the Grenadier enemy/s appears in game and when they are defeated. The following method uses exactly the same steps for both levels. The existing code within the game has been set up to allow you to switch back to ambient music when all Grenadier enemies have been defeated.

Select the Grenadier Activator GameObject, observe the ToggleGameObjectActive script in the Inspector

Expand the dropdown for the Targets Variable and change the Size parameter from 1 to 3 in Level01 and also from 0 to 2 in Level02

Drag and drop the GameObject Combat Music AudioSource GameObject and the Mute Ambient Music created in previous steps to assign these GameObjects to the new additional Targets Variables for Element 1 and 2 in Level01 and Element 0 and 1 in Level02

Figure 11.3.10 Adding Additional Variables to ToggleGameObjectActive Script and Assigning Combat Music AudioSource and Mute Ambient Music GameObjects

Select the GrenadierDeadEvent or BothGrenadiersDeadEvent GameObject in the Hierarchy, depending on which level you are working on, using the following path:

(Level01 Scene) > Enemies > GrenadierDeathCounter > GrenadierDeadEvent

(Level02 Scene) > Enemies > GrenadierDeathCounter > BothGrenadiersDeadEvent

Observe the SetGameObjectActive script in the Inspector

Expand the dropdown for the Targets Variable and change the Size parameter from 0 to 2 in both levels

Drag and drop the UnMute Ambient Music GameObject and the Mute Combat Music GameObjects created in previous steps to assign these GameObjects to the new additional Targets Variables to Element 0 and 1 respectively

Figure 11.3.11 Adding Variables to GrenadierDeadEvent SetGameObjectActive Script and Assigning UnMute Ambient Music and Mute Combat Music GameObjects

When the Grenadier enemy will be spawned/activated in Level01 GrenadierActivatorTrigger after collecting the third crystal, the Mute Ambient Music GameObject will be Enabled and Mute AudioSource script will activate the Mute parameter on the Ambient Music AudioSource, instantly silencing it. At the same time, the Combat Music AudioSource will be Enabled, and because it has the Play On Awake parameter activated, the combat music will begin to play.

When the player walks through the Trigger Area GameObject named GrenadierActivatorTrigger in Level02, the InteractOnTrigger script will Enable the Combat Music AudioSource and Mute Ambient Music GameObjects assigned to the ToggleGameObjectActive script found on the GrenadierActivator GameObject. As with Level01, this will mute the Ambient Music and start the Combat Music playing.

When the Grenadier enemy/s has been defeated/killed in both levels, the SetGameObjectActive script on either the GrenadierDeadEvent or BothGrenadiersDeadEvent GameObject will Enable the UnMute Ambient Music and Mute Combat Music GameObjects. This will cause the Mute parameter on the assigned Ambient Music AudioSources to be unchecked and thus audible again and, at the same time will set the checkbox for the Mute parameter on the Combat Music AudioSource silencing it.

In effect, a trick has been played on the player as the ambient music never actually stopped playing during the Grenadier fight, but was just temporarily muted. Likewise, the combat music has not actually stopped playing; it is now just inaudible.

I would advise you at this point to play through each level to check/confirm all of the statements are working as described in your 3D GameKit. If something is not quite working correctly, don’t be disheartened. Even after years of experience working on Game Audio projects in Unity, I still find it unusual if I manage to get something as complex as this working correctly on my first attempt.

Troubleshooting your own work is an essential skill that you need to develop if you want to continue in Game Development. If your adaptive or interactive music is not working as intended, I would advise you to read through the setup instructions to make sure you have not made a mistake or missed a step. If possible, try tracing the ‘signal or logic flow’ from the GameObjects and Components using the description of the various processes and what is supposed to be happening at each event in the game as provided earlier.

Resources

The following examples include a number of resources, many of which can be licensed under the Creative Commons Attribution that permits you to use these compositions for educational and not for profit applications. These resources will all have the specific licensing information available; please read it thoroughly and comply with the guidelines. (All links are active at the time of writing.)

https://assetstore.unity.com/audio/music

https://cambridge-mt.com/ms/mtk/

www.bigfishaudio.com

https://incompetech.com/music/

5 quick tips

When editing music, make sure you set the tempo of your DAW to match the tempo of your music. This will make it much easier to count how many bars of music there are and will reduce the chance of clicks or pops by editing using quantisation to a grid.

If your musical edit or arrangement still feels like it is lacking energy at the Loop Point, consider also adding in an additional single percussion hit at the beginning of the Loop Point to reinforce and provide additional energy. If this is not appropriate for your musical arrangement, or it still doesn’t have the effect you require, consider revisiting and re-editing your arrangement to make sure the energy levels between the beginning and end of the loop are consistent.

Editing music for use in a Game Audio system requires a different thought and mixing philosophy than conventional music. You may need to create several revisions of all of your musical compositions to make the musical transitions sound natural and smooth.

If you are using a music track that has already been mastered or normalised, make sure the combined outputs of the additional Tail Tracks and the original audio do not overload and clip the output in your DAW, potentially causing digital distortion. If this happens when listening to or checking the Loop Point, reduce the volume of both tracks and re-normalise the music audio file after exporting/rendering.

If you are using ‘mutually exclusive’ scripts such as mute and unmute or fade in and fade out to control the same parameter on the AudioSource, make sure only one of these pairs of GameObjects is Enabled at any time to avoid any unexpected issues with ‘parameter fighting’.

Tip

When mixing a typical music track, you often want it to sound really loud and full. You may find when attempting to use this approach in an interactive game that your music takes up too much of the frequency content of your mix and that other SFX or dialogue are becoming obscured or frequency masked. It is very common to use somewhat extreme EQ in the mastering stage to carve out room for the other audio elements of the mix. Such EQ changes are unlikely to ever be used when the music is intended to be heard without visual accompaniment, but alongside other sound design elements, this can help create more space within the mix as these frequency ranges will be occupied by other audio elements.

Chapter 11 practical tasks

The practical task for this chapter is to edit and implement a dynamic, interactive, and/or adaptive musical score using whichever method or combination of methods you choose. If you have your own unique ideas for interactive or adaptive music, then feel free to try to implement it in your 3D GameKit Project.

The steps required to implement adaptive music are by far the most complicated, multistep Audio Implementation example within this book. If you did manage to get your adaptive music working, well done.

If you want to further challenge yourself, try adapting the instructions to include further use of the AudioSourceFadeOutVolume script and AudioSourceFadeInVolume to make all of the transitions involving switching to combat music sound as seamless and professional as possible.

If even this seems too easy, or if you’ve managed to successfully integrate both approaches separately, why not try going even more ‘off book’ and integrating the Interactive and Adaptive music techniques together in combination with some of your own original music implementation ideas?

I would advise that if you intend to share your project online as a playable demo or video captured gameplay, make sure that the music is composed by yourself or is royalty free/licensed under Creative Commons. This is to avoid not only legal repercussions but also the video being silenced or an automatic takedown notification if using copyrighted music on popular video hosting or streaming services.

12 Unity Mixer routing and effects and additional audio scripts

DOI: 10.4324/9781003055167-12

This chapter will explain how to set up the Unity Audio Mixer within the game to create a dynamic, interactive, and adaptive audio mix. It covers how to route AudioSources through the Unity Mixer and various Unity Audio Effects such as EQ, Ducking, Distortion, Delay, and Chorus. You will learn to apply these in a variety of creative ways, and also how to change the audio mix balance when the game is paused. Finally, you will investigate how the SFX and Audio Options have been implemented in the Pause Menu for Level01 and Level02 as well as on the Start –Front End level.

The Unity Audio Mixer works in a similar way to the mixer in a conventional DAW. It allows you a great deal of control, enabling you to route audio from your AudioSources to Unity Audio Mixer Groups/channels in this mixer. You can then begin to mix this audio using a number of parameters for Volume, Solo, Mute, Auxiliary Sends and Receivers, and a number of Unity Audio Mixer Effects/plugins such as High and Low Pass Filters, Distortion, Chorus, Compression etc.

A simplistic view of the basic signal flow for the audio in Unity would be:

Audio is triggered via Play On Awake parameter or by code script > Audio Listener > AudioSource plays sound > AudioSource is routed to Unity Mixer > Audio is played through speakers/headphones.

Unity Audio Mixer

You can view the Audio Mixer in Unity by clicking on the Window Menu and selecting Audio Mixer.

Figure 12.1.1 Unity Audio Mixer Window Menu

You can then dock the Audio Mixer Panel anywhere in your Window Panel Layout. I would normally place this by the Project Panel near the bottom alongside the Project Panel as shown in the images within this chapter, but as with all Panel Layout options in Unity, this is entirely personal preference.

You can see a number of parameters in the Audio Mixer Panel as indicated in Figure 12.1.2.

Mixers – By default you will have one Audio Mixer. It is possible to have several Audio Mixers and route these into one another. In the following examples, for the sake of simplicity, only a single Audio Mixer will be used.

Snapshots – Mixer Snapshots are used to save various settings for the Audio Mixer that you can activate using scripts. (One use could be for a Pause Menu to silence the in-game ambience when the game is paused.)

Groups – Groups are what Unity calls ‘Channels’, ‘Tracks’, or ‘Auxiliaries’ in a conventional DAW.

Views – You can set up several Views in the mixer; this will allow you to turn the visibility of individual Audio Mixer Groups on and off.
On the Audio Mixer Groups you also have a number of controls.

Volume – This will control the volume of your Audio Mixer Group using a logarithmic fader from −80 dB to +20 dB. (As with standard mixing desks and DAWs, 0 dB is Unity Gain where the signal is neither attenuated/turned down nor increased/boosted.)

Solo – This will solo this group so you only hear the AudioSources that are assigned to it.

Mute – This will mute this group so you don’t hear the AudioSources that are assigned to it.

Bypass – This will bypass the effects on this group so you hear the AudioSources that are assigned to it without any effects

Add – This button will allow you to add effects to the Audio Mixer Group.

Figure 12.1.2 Unity Audio Mixer Panel

I did state earlier in the book that Unity, and game engines in general, are not able to boost or increase the gain or level of an AudioClip beyond playing the audio file back as loud as the current file has been normalised to. This is true when using the AudioSource Component, but as you can see, it is possible to increase the maximum volume of the AudioClip by setting the Group Volume fader higher than 0 dB. Games, however, tend to use the Audio Mixer in slightly different ways to conventional DAWs, as discussed later in the chapter regarding mixing approaches.

You also need to be aware of drastically increasing the volume playback of an audio file normalised to −1 dB in the Unity Audio Mixer to avoid causing digital overload or clipping.

As a general rule, there are not the same strict requirements or specifications for overall average volume/mix levels for video games, especially compared with film, TV, and radio. Likewise, you should not attempt to mix your game using limiters and compression to drastically reduce the dynamics, like a modern piece of music. Games are often played for extended periods of time and do require dynamic changes from louder to quieter sections to avoid fatiguing the player’s ears. The Sony Audio Standards Working Group (ASWG) has set out some recommendations relating to average volume measured over a longer period of time. The aim of this is to attempt to ensure their first party titles’ average volume levels are not drastically different from one another.

The Sony ASWG recommends an average volume of −23 LUFS (Loudness Units, relative to digital Full Scale) +/− 2. If this is an area you are interested in, feel free to research this further. If you do not wish to learn about or implement this, please try to ensure the loudest section of the game does not peak above −1 dB in the Unity Audio Mixer Master Group and that on average your game volume level is between −18 dB and −30 dB. Adjust the individual AudioSources, Unity Mixer Groups, or Unity Mixer Group Master fader to attempt to achieve this, but remember you should have particular shorter sections of the game that are louder or quieter than others to create contrast.

Creating groups and assigning AudioSources

You can also add additional Groups/Channels to your mixer by clicking on the + button adjacent to the Groups heading.

Groups use the same Parent/Child relationship as GameObjects in the Hierarchy. To assign a Group as a Child of another Parent Group, select it by left clicking and holding to then drag and drop this Child onto the Parent, much like rearranging the structure of GameObjects in the Hierarchy.

I would suggest you begin by creating a number of groups for Ambient SFX, Player SFX, Enemy SFX, Dialogue, Music etc. This will allow you to quickly raise or lower the volume of the sounds routed through this group and use ducking, as well as to solo or mute these sounds quickly when mixing your game. You do not however, need a separate Group for every individual sound as you may expect when using a DAW. Generally, these volume controls are for quickly adjusting the balance of the volume of Groups featuring multiple AudioSources, such as the Chomper’s footsteps. If you want to tweak the volume of a single AudioSource within the Group, you can still do this on the individual AudioSource Component.

Figure 12.2.1 Audio Mixer Group Structure and Hierarchy Signal Flow

Figure 12.2.2 Unity Audio Mixer Group Hierarchy

I would advise initially creating a number of groups as shown in Figures 12.2.1 and 12.2.2, using the Parent/Child relationship in the Audio Mixer. This will give you the flexibility to adjust, for example, all of the Dialogue or Ambient AudioSources without requiring you to modify the volume of each AudioSource individually.

You can assign AudioSources to the groups by selecting the AudioSource GameObject in the Hierarchy and clicking on the Output parameter of the AudioSource in the Inspector. This will bring up a menu allowing you to select from any of the Audio Mixer Groups you have previously created.

Figure 12.2.3 Assigning AudioSource to Audio Mixer Group

If you assign the SwingStaff AudioSource to the Player SFX Audio Mixer Group. Now if you play the game with the Audio Mixer Panel in view, you will see that the AudioSource Output from the Swing Staff AudioSource will play through the Assigned Player SFX Mixer group.

It is worth noting that if an AudioSource is not assigned to a Mixer Group, it will still be heard but is effectively bypassing the Unity Audio Mixer entirely and will be routed straight out of your Master Left and Right outputs on your computer. You may find that some sounds can still be heard when soloing a group. In this case, you will need to locate the offending AudioSource and assign a Mixer Group Output to make full use of the Unity Mixer Solo and Mute features.

Adding effects to Audio Mixer Groups

As discussed earlier, you will now explore adding effects to the Audio Mixer Groups.

Unity comes with a number of audio effects, including:

Send

Receive

Duck Volume

Low Pass

High Pass

Echo

Flange

Distortion

Normalise

ParamEQ

Pitch Shifter

Chorus

Compressor

SFX Reverb

Low Pass Simple

High Pass Simple

Resonance Audio Renderer

You can add these to a Group by clicking on the Add button and selecting the effect you want. Right clicking in the effects section of the Audio Mixer Panel will also bring up the menu to add an effect at the top or bottom of the effects chain.

Figure 12.2.4 Adding Effects to Audio Mixer Group

Tip

The order in which you add your effects to the group is important. As in a DAW, the effect at the top of the chain processes the audio first, then the effect second from the top, and so on. If you have a number of effects, sends etc. placing the Attenuation effect before or after a Compressor, or choosing to place the Low Pass Filter first or last in the chain, will result in different audio outcome.

After adding your effect, you can control the parameters by selecting the Audio Mixer Group and viewing the Inspector Panel.

Figure 12.2.5 Viewing and Adjusting Audio Mixer Effects in Inspector

Consider setting up a short Volume Ducking effect on the Ambience Audio Mixer Group that is activated by a Send on the Player Death SFX Audio Mixer Group. This should correspond with the screen quickly fading to black, before respawning Ellen at the nearest checkpoint.

Begin by assigning all of the Ambient SFX AudioSources you have created within your 3D GameKit to the Ambient SFX Mixer Group

Create an additional Audio Mixer Group as a Child of the Player SFX Audio Mixer Group and name this Player Death

Locate Ellen’s EmoteDeath AudioSource GameObject that will play a SFX when Ellen has been killed in the game. Ensure you have added an AudioClip/s to the RandomAudioPlayer script and mixed the volume so this is clearly audible in the game

Assign the EmoteDeath AudioSource to the Player Death Audio Mixer Group

Next, add in a Duck Volume Effect on the Ambient SFX Audio Mixer Group

Add in a Send Effect on the Player Death SFX Group

Select the Player Death SFX Group in the Audio Mixer and observe the Inspector

Click on the None parameter adjacent to the Receive Variable for the Send effect

Select the Ducking effect for the Ambient SFX Audio Mixer Group. If your Mixer Groups have been named as in the example, this will read Ambient SFX\Duck Volume

Figure 12.2.6 Send Effect from Player Death Audio Mixer Group to Ambient SFX Audio Mixer Group

Next, adjust the new Send level slider parameter fully to the right to set it to 0.00 dB

This will send the full signal of the Player Death SFX group to the Duck Volume sidechain input on the Ambient SFX Mixer Group.

Finally, select the Ambient SFX Mixer Group in the Audio Mixer Panel and set the Duck Volume settings in the Inspector as shown in Figure 12.2.7.

Figure 12.2.7 Setting Duck Volume Parameter and Send Level Effects

If you now play the game, provided everything has been set up as explained in these steps, you should hear a noticeable volume reduction of the ambience when Ellen is killed and the death grunt plays. The Attack Time and Release Time parameters of the Duck Volume have been set up to roughly correspond with the visual fade out to black before respawning. Depending upon how long your death Audio Asset is, these times will likely need to be adjusted to correspond with your specific project.

You may also have noticed that when Unity is in Play Mode, an Edit in Play Mode button appears near the top middle section of the Audio Mixer Panel.

Figure 12.2.8 Audio Mixer Edit in Play Mode Button

If you left click to activate/enable this button while Unity is in Play Mode, this will allow you to adjust any of the Audio Mixer parameters and hear the change instantly while listening to the audio mix in the game.

The EDIT IN PLAY MODE for the Unity Audio Mixer is the ONLY MODE in which Unity will save any changes you make when exiting Play Mode and returning to Edit Mode.

Adding effects to AudioSources

You can also add Unity’s Audio Effects directly onto any AudioSource. Select the AudioSource GameObject in the Hierarchy and then click the Add Component button. From here you can type in the name of an Audio Effect, or search by clicking on the Audio category and then choosing an effect from the list of available options.

Figure 12.3.1 Adding Effects to AudioSource Component

The parameters for the Audio Effect will now appear in the Inspector.

Figure 12.3.2 Audio Low Pass Filter Effect Configurable on AudioSource 3D Graph

As you may notice, certain audio effects such as the Low Pass Filter also appear as controllable parameters over distance on the AudioSource 3D Settings graph.

You can set these to static parameter settings using the sliders, or you can double click on the purple line (in this case for the Low Pass) to change the effect values over distance. The slider value is now displaying Controlled By Curve as the effect values are now controlled on the graph over distance, much like changing the volume using the Min and Max Distance parameters.

Figure 12.3.3 Custom Curve Created for Audio Low Pass Filter Controlling Cut-Off Frequency over Distance

One example of controlling effects over distance could be using the Low Pass Filter to reduce the high frequencies as you get farther from the AudioSource. This will begin to emulate the natural reduction in high frequencies you would expect to happen in the real world when getting further from a sound source. This is featured on the LevelGatewayAudio GameObject in the Level01 With Audio project.

Creating Audio Mixer Snapshots

Audio Mixer Snapshots allow you to save all the volume and effect settings of your Audio Mixer Groups, to then recall these while the game is running using code. One example where Audio Mixer Snapshots are commonly used would be in a Pause Menu. You would expect to hear the mix of the game change somehow while the game is Paused, to let the player know the game is not currently running and is in a Paused State. This could be done with volume reduction, EQ, adjusting reverb send levels, or any number of different creative processes.

Using the previous example, it would be very common to have one Snapshot when the game is playing/running normally, and another separate Snapshot when the game is Paused.

You can create a new Audio Mixer Snapshot by clicking on the + button to the right of the Snapshots heading.

Figure 12.4.1 Creating Audio Mixer Snapshots

This will create a copy of all currently selected Audio Mixer settings and store these as an Asset within the Project Panel folder structure.

Figure 12.4.2 Renaming Snapshots and Setting Default

You can now right click on the Snapshot to rename them to make them easier to find/use in the project.

To change the effect or volume settings for each Audio Mixer Snapshot, select that Snapshot, and adjust the parameters. When recalling these Snapshots while the game is running, the parameters will update from their current settings in the game to reflect the selected Snapshot parameter settings.

To set which Snapshot will be used when starting the game, right click on the Snapshot name and select Set as Start Snapshot.

The starting default Audio Mixer Snapshot name will now have a small grey star, as indicated in Figure 12.4.2. I would advise setting the In-Game/UnPaused Snapshot as the default, so the player will hear the audio using these settings when beginning the game.

Next, select the GameObject MenuCanvases. You will find a script in the Inspector called StartUI. This has two variables that have been created called Pause Snapshot and UnPause Snapshot.

Assign your Pause and UnPause Unity Audio Mixer Snapshots to the relevant variable by clicking on the small circular icon immediately to the right of the None (Audio Mixer Snapshot) Variable, and selecting it from the list.

The Snapshot Transition Time Variable allows you to set the time, in seconds, that the StartUI script will take to transition between the various Pause/UnPause Snapshots when the player presses the Esc key to enter or exit the Pause Menu.

Now, select the Pause Snapshot on the Unity Audio Mixer and make a change that will be clearly audible, such as reducing the volume of the Ambience or Music Audio Mixer Group.

Figure 12.4.3 Assigning Audio Mixer Snapshots to Start UI Script Variables on MenuCanvas GameObject

Finally, playtest your game to ensure the Audio Mixer Snapshots are working as you intended when Pausing and UnPausing.

Pause Menu – settings

The player is able to press the Escape (Esc) key and Pause the game; this stops all Enemies from moving and displays a number of options.

Figure 12.5.1 Pause Menu Buttons

Audio Implementation has already been set up for a One Shot highlight SFX to play when moving the mouse over each of the three options and the X Exit button in the top right-hand corner.

Audio Implementation has also been set up to play a One Shot Confirm SFX when clicking on each of these buttons.

Options select SFX

The SFX implementation for the existing Mouse Over/Highlight and Confirm SFX can be located as a variable on the On Click () Event Button script, using the following Level01 Hierarchy path:

MenuCanvases > PauseCanvas > BG > OptionsButtonCanvas > UIButton

The Confirm SFX uses the On Click function and the variable on the Button script.

Assigning AudioSources, and setting these to play, works using the exact same functionality as described for the InteractOnTrigger script. Drag and drop your Audio Asset from the Project Panel directly into the variable directly underneath AudioSource.PlayOneShot.

This sound is then triggered and played through the attached MenuCanvases AudioSource when the player clicks on the Options Button.

Figure 12.5.2 Button Script Component with AudioClip Variable for On Click Event () Located on UI Button GameObject

Options highlight SFX

The SFX for the Mouse Over/Highlight/Pointer Enter SFX for the ‘Options’ button can be found on the Pause Menu by following the exact same Hierarchy path:

MenuCanvases > PauseCanvas > BG > OptionsButtonCanvas > UIButton

The Highlight/Mouse Over SFX uses the Pointer Enter function variable on the Event Trigger Script found at the bottom of the Inspector. Again, this uses the exact same controls for assigning an AudioSource and instructing this to play as the InteractOnTrigger script.

Drag and drop your Audio Asset into the variable directly underneath AudioSource.PlayOneShot.

This sound will then be triggered and play through the same attached MenuCanvases AudioSource when the player moves the mouse over the Options Button.

Figure 12.5.3 Event Trigger Component with AudioClip Variable for Pointer Enter Event () Located on UI Button GameObject

The majority of the other buttons in the Pause Menu use an identical setup for the On Click/Confirm SFX and the Pointer Enter/Highlight SFX.

They can be found using the following Hierarchy paths in either Level01 or Level02:

MenuCanvases > PauseCanvas > BG > RestartButtonCanvas > UIButton

MenuCanvases > PauseCanvas > BG > BackButtonCanvas > UIButton

MenuCanvases > PauseCanvas > BG > UICloseButton

MenuCanvases > OptionsCanvas > BG > AudioButtonCanvas > UIButton

MenuCanvases > OptionsCanvas > BG > ControlsButtonCanvas > UIButton

MenuCanvases > OptionsCanvas > BG > BackButtonCanvas > UIButton

MenuCanvases > OptionsCanvas > BG > UICloseButton

MenuCanvases > AudioCanvas > BG > UICloseButton

Audio Options in Pause Menu

You may have also noticed that inside the Audio Options there are sliders to control the volume of the Master fader, Music Volume, and SFX volume. It is possible to have these sliders control Audio Group Channels in the Audio Mixer.

Begin by checking that you have set up your Audio Mixer Group structure correctly.

Next, ensure you have assigned all of the AudioSources in the game to the correct Audio Mixer Group.

Finally, ensure you have created one Audio Mixer Snapshot with relevant volume, effect settings for In-Game/UnPaused, and one for when the game is Paused.

Figure 12.5.4 Example Audio Mixer UnPaused Snapshot Settings

Figure 12.5.5 Example Audio Mixer Paused Snapshot Settings

Next, you will need to ensure that the relevant Audio Mixer Groups volume controls are able to be altered by a code/script Component. The aim is to link together the slider for Master, Music, and SFX visual soldier controls in the Pause Audio Options Menu with the Audio Mixer Group Volume parameter in the Unity Mixer.

Start by left clicking to select the Master Audio Mixer Group. Observe the Inspector Panel and right click on the Volume name below Attenuation to show the Expose settings.

Figure 12.5.6 Exposing Volume Parameter of Master Fader Using Inspector

Click on Expose Volume (of Master) to script.

If you now look in the top right of the Unity Mixer next to Exposed Parameters, you should see the number 1.

You can left click on Exposed Parameters and right click on MyExposedParam to rename it MasterVolume.

Figure 12.5.7 Renaming Exposed Volume Parameter of Master Audio Group

The GameObjects for each Master, Music, and SFX sliders can be found using the following Hierarchy paths in Level01 and Level02:

MenuCanvases > AudioCanvas > BG > MasterVolumeSlider

MenuCanvases > AudioCanvas > BG > MusicVolumeSlider

MenuCanvases > AudioCanvas > BG > SFXVolumeSlider

You will need to add in the MixerSliderLink script to each of these GameObjects listed previously.

The Exposed Volume Parameter for each fader Group on the Unity Mixer should be assigned to the corresponding Mixer Variable on each GameObject listed previously. For the Master Volume Slider, you would add in the MixerSliderLink Script and then add in your Exposed Parameter name you just created. If you followed the example in the previous step, you will have named this MasterVolume.

Next, set the upper and lower limits for how much the player is able to adjust the Master Volume Slider. If you are unsure of how much control to give the player over the audio mix, then leave these to the default settings of 0 and −80 respectively. The player will be able to completely reduce the volume of the Master, Music, or SFX from silent to full volume.

Finally, assign the Audio Mixer Group into the Mixer parameter by right clicking on the small circular icon to the right of the None (Audio Mixer) Variable. Select the Audio Mixer you want to assign. If you have followed the instructions, you should only have a single available Audio Mixer Asset called AudioMixer.

Figure 12.5.8 Adding Mixer Slider Link Script to Master Volume Slider GameObject and Setting Variables

Play the game and check the Master Audio Mixer Group Volume parameter in the Unity Audio Mixer Panel is now being controlled via the Audio Options in the Pause Menu. You should be able to not only hear but also see the Master Audio Group in the Audio Mixer moving up and down in relation to the current value of the visual Master Volume Slider in the Pause Audio Options Menu, as it is moved right and left respectively.

Figure 12.5.9 Confirm Visual Link Between Master Volume Parameter in Scene View Pause Menu and Master Audio Group in Audio Mixer Panel

Follow these same instructions to set up the Volume parameter of the Music and SFX Mixer Groups to be controlled by the in-game Pause Menu Audio Option sliders. If you apply your changes to the Parent MenuCanvases Prefab GameObject, these settings will be applied to both Level01 and Level02.

If you adjust the audio settings in the Pause Menu Audio Options while Unity is in Play Mode, this is effectively moving or changing the slider for the Pause Menu Audio Options and changing this to match the current Exposed Volume Parameter on the various Audio Mixer Groups. When starting any of the levels, the visual slider in the Audio Options takes its starting value or position relative to the starting Audio Mixer Snapshot values for the Exposed Audio Mixer Group Volume Parameters.

You will notice however, that Unity may only seem to ‘save’ the default settings for the various Audio Options if the game is started from the Start – Front End level and played naturally through Level01 and Level02, rather than opening directly into the Level01 or Level02 Scene and pressing the Unity Play button. For instance, if you begin playing the game from any level and then immediately Pause the game and adjust the Audio Options from within the Pause Menu, you will hear this change reflect while Unity is still in Play Mode. If you were to then immediately take Unity out of Play Mode and return to Edit Mode, then press the Play button again to enter Play Mode a second time, it may appear that the visual slider position has reverted back to a different setting when viewing the Pause Menu Audio Options.

This is because the default visual values when entering Play Mode in Unity are taken from the Start Snapshot volume settings of the Exposed Parameters of the Audio Mixer Groups. When in Play Mode, if the player were to Pause the game and change any of the Audio Options sliders, then this would remove the volume control from the Audio Mixer directly and update/change the current Audio Mixer Exposed Volume Parameter, based upon the visual slider position in the Pause Menu.

If you want to ‘save’ your own default Audio Options settings, then be aware that whatever the volume of the Exposed Audio Mixer Parameters used for the Default snapshot will then set the initial value for the visual slider in the Pause Audio Menu Options, rather than, as you may expect, the Pause Audio Menu Options setting the Audio Mixer when the level begins.

Audio Options in Pause Menu

You will need to add in the sound effects implementation and Mixer Slider Link Script Components separately for the Start – Front End Scene as the options and visuals are slightly different and require that this be set up separately. Due to this, it has not been linked to the same Prefab as shared by the Pause Menu for Level01 and Level02.

The GameObjects for the Mouse Over Highlight and Confirm SFX Implementation can be found using the following Hierarchy paths on the Start – Front End Scene:

StartMenuCanvas > MenuBackground > StartButton

StartMenuCanvas > MenuBackground > OptionsButton

StartMenuCanvas > MenuBackground > ExitButton

The GameObjects listed use the same Button and Event Trigger scripts as used for their in-game Pause Menu counterparts. The AudioSource can be found on the Inspector for the Parent StartMenuCanvas GameObject.

The GameObjects for each Master, Music, and SFX visual sliders for the Pause Menu Audio Options can be found using the following Hierarchy paths in the Start – Front End Scene:

OptionsCanvasMaster > AudioCanvas > BG > MasterVolumeSlider

OptionsCanvasMaster > AudioCanvas > BG > MusicVolumeSlider

OptionsCanvasMaster > AudioCanvas > BG > SFXVolumeSlider

You will need to add in the Mixer Slider Link Script Component to each of these GameObjects and assign in the Exposed Parameters you have created that link each visual slider to the corresponding Audio Mixer Group. Finally, assign the Audio Mixer Variable and set the Max and Min Attenuation Variables the same as the identical Pause Audio Options GameObjects.

Front End – Start Scene Music and Background SFX implementation

It is a creative choice if you want to only feature the menu-clicking SFX on the Start – Front End Scene, or you want to include background music, ambience, and SFX for the Chomper enemy visible on the left-hand side of the screen. You can add in an AudioSource for looping background music, and if you want, an AudioSource for looping background ambience by right clicking in the Hierarchy and creating an AudioSource GameObject.

To add in SFX for the Chomper, begin by selecting the ChomperFrontEnd GameObject in the Hierarchy. You will also notice that this particular Chomper enemy does not belong with the main Chomper Prefab.

Figure 12.5.10 RandomAudioPlayer GameObjects for Chomper on Front End Scene

This Chomper has been set up in exactly the same way as the main Chomper enemies in Level01 and Level02. The Chomper on the Start – Front End Scene uses the same ChomperBehavior script and GameObjects featuring an AudioSource and RandomAudioPlayer Components. You can even assign the Audio Assets you have already created to these RandomAudioPlayer AudioSource GameObjects in exactly the same way.

I would advise however, that you adjust the Spatial Blend parameter on the AudioSource and set this to 2D. The actual Start – Front End menu screen is in two dimensions, or 2D, and the Chomper enemy is actually positioned quite far away from the Audio Listener. In this scenario, as the Chomper is not actually moving around in the level, it is best to use 2D spatialisation and then take advantage of the Stereo Pan parameter on the AudioSource. This will enable you to pan all of the Chomper sounds to the left-hand side corresponding with the Chomper’s location on screen.

Figure 12.5.11 Setting 2D Spatial Blend and Stereo Pan Parameters on Front End Chomper AudioSources

5 quick tips

You can make use of other creative audio effects in the Unity Audio Mixer to apply effects set to different parameter settings for the Pause and UnPause Snapshots. The Snapshot transitions can be used not only to change the volume of the Audio Mixer Groups but also to automate between any parameter setting on the effects. Try setting up a Low Pass Filter and a High Pass Filter on the Music Audio Mixer Group to reduce the frequency bandwidth of the music when the game is Paused.

The Menu/UI SFX clicks may seem very simple and quick to create ‘as it’s just a click type SFX’. However, they are often one of the most overlooked and difficult sound design skills to master. Think about how you can incorporate elements of your sound design style for your project within these menus. Try to encapsulate your sound design for the project within the Menu/UI SFX, ensuring these are consistent, reinforce and essentially sum up your sound design theme for the Project. Believe me, this is much harder to do in practice than it sounds.

You may find that your Audio Mixer Groups Hierarchy has to change as your project grows in complexity. This is entirely normal and expected. The Audio Mixer Group Routing/Hierarchy Matrix included in this chapter is only a basic guide or starting off point; feel free to modify this to your own specific requirements.

It can be helpful to create an additional Audio Mixer Group as a Child of the Master Audio Mixer Group on the Audio Mixer Hierarchy called ‘Temp’. You can now assign AudioSources temporarily to this group and use the Solo button on this new Audio Mixer Group if you want to hear an individual AudioSource solo’d in the game. This method will only work however, if every AudioSource in the current scene has been assigned to an Audio Mixer Group.

Think about using the Duck Volume Effect in other places within your game to produce a more interactive sounding mix. In video game mixing, it is quite common to very subtly duck the ambience and/or the music when the dialogue is playing. This can help ensure the dialogue can be heard clearly without needing to be mixed at an uncomfortably loud level.

Tip

If you are unsure of how you should change the audio mix to signify that the game is now Paused, revisit some of your favourite games to take some inspiration. Listen to how the game mix changes in a Paused verses UnPaused state.

Does all the in-game audio become silenced, or is the mix now quieter using either volume or reduced frequencies? Does the music stop playing, or is there specific pause menu music, or is there something completely different happening?

Chapter 12 practical tasks

The practical task for this chapter is to begin configuring the Unity Audio Mixer to begin crafting the final mix and ultimately begin to make full creative use of the mixing skills discussed in this chapter.

Remember, you can still adjust the volume of individual AudioSources directly.

You DON’T and SHOUDN’T have to create a separate Audio Mixer Group for each AudioSource.

This stage is to balance overall groups of sounds, to make use of interactive effects to create a dynamic mix, and to add in the required Audio Implementation for the Pause Menu.

Add in a number of Audio Mixer Groups to the Unity Audio Mixer

Assign your various AudioSources to these groups

Consider setting up Ducking effects to lower the volume of the music or ambience when the dialogue plays to make space within the mix

Set up Audio Mixer Snapshots for your in-game mix and when the game is paused

Add in the SFX for the Pause Menu buttons including linking the Audio Options in the audio section of the Pause Settings

13 Bonus chapter – expanding/improving upon existing implementation

DOI: 10.4324/9781003055167-13

This chapter will cover how to add in audio to a number of mechanics in the original 3D GameKit, improving and expanding upon the current Audio Implementation. If you have completed the earlier chapters, this will help lift the standard of the audio in your project to that approaching a professionally released game.

There are many different places to add in additional sounds on the 3D GameKit Project, such as:

Adding SFX to Ellen’s Shield Mechanic

Adding SFX for Ellen’s Respawn Mechanic

Adding Additional Ambient SFX to the Staff Weapon on the Podium in Level01

Adding Start and Stop SFX for the Rising Platforms

Adding Additional SFX to Chomper Death Particles

Adding in a One Shot Sound at the Beginning of Spaceship Arrival Animation at End of Level02

Adding SFX when Ellen loses a Health Point or Regains Health

Adding SFX when Ellen’s Remaining Health Points are Low

Adding SFX to the Dialogue UI Animations

You will also find a number of additional audio scripts included with both the With Audio and Silent projects that have been created specifically to help you implement the ideas earlier and, more importantly, any of your own ideas for this project. An explanation of how each individual Script Component can be used has been included in the following.

Additional audio scripts

Audio Countdown Disable Object

This script will allow you to set a time in seconds from when the GameObject containing the script is Enabled, until the Count Down From timer reaches 0 and it Disables the GameObject assigned to the GameObject to Disable variable.

Figure 13.1.1 AudioCountdownDisable Script as Displayed in Inspector

Audio Countdown Enable Object

Figure 13.1.2 AudioCountdownEnableObject Script as Displayed in Inspector

This script will allow you to set a time in seconds from when the GameObject containing the script is Enabled, until the Count Down From timer reaches 0 and it Enables the GameObject assigned to the GameObject to Enable variable.

Audio Disable After Finish Playing

Figure 13.1.3 AudioDisableAfterFinishPlaying Script as Displayed in Inspector

This script will Disable the AudioSource GameObject when the AudioClip has finished playing.

Audio Disable GameObject

Figure 13.1.4 AudioDisableGameObject Script as Displayed in Inspector

This script will immediately Disable the GameObject attached to the Disable This GameObject variable.

Audio Enable GameObject

Figure 13.1.5 AudioEnableGameObject Script as Displayed in Inspector

This script will immediately Enable the GameObject attached to the Enable This GameObject variable.

Audio Listener Controller

Figure 13.1.6 AudioListenerController Script as Displayed in Inspector

This script will allow you to change the Audio Listener from the game camera to Ellen as discussed in Chapter 6.

Audio Play Random Audio Player

Figure 13.1.7 AudioPlayRandomAudioPlayer Script as Displayed in Inspector

This script will trigger the RandomAudioPlayer AudioSource GameObject, which is attached to the Play Random Audio Player GameObject variable, to Play when the GameObject it is a Component of, is Enabled.

AudioSource Fade In Volume

Figure 13.1.8 AudioSourceFadeInVolume Script as Displayed in Inspector

This script will Fade In the volume of the assigned AudioSource to the Target Volume over the amount of time set in seconds on the Fade In Time In Seconds, when the GameObject it is a Component of is Enabled.

This script cannot be used alongside a RandomAudioPlayer script, as the two scripts will fight over the volume control of the AudioSource attached to the variable.

AudioSource Fade Out Volume

Figure 13.1.9 AudioSourceFadeInVolume Script as Displayed in Inspector

This script will Fade Out the volume of the assigned AudioSource to the Target Volume over the amount of time set in on the Fade Out Time In Seconds, when the GameObject it is a Component of is Enabled.

This script cannot be used alongside a RandomAudioPlayer script, as the two scripts will fight over the volume control of the AudioSource attached to the variable.

Damageable Enable GameObject

Figure 13.1.10 DamageableEnableGameObject Script as Displayed in Inspector

This script will Enable a GameObject when the assigned character’s health reaches the value specified as described later in this chapter.

Mute AudioSource

Figure 13.1.11 MuteAudioSource Script as Displayed in Inspector

This script will mute the AudioSource attached to the Mute This Audio Source Variable when the GameObject it is attached to, is Enabled.

UnMute AudioSource

Figure 13.1.12 UnMute AudioSource Script as Displayed in Inspector

This script will unmute the AudioSource attached to the Un Mute This Audio Source variable when the GameObject it is attached to is Enabled.

OneShotAudioRandomLocation script

Chapter 3 discussed the importance of variation when building ambience in levels. The goal of a Game Audio Sound Designer should be to increase and maintain the immersion of the player; one of the easiest ways to break this immersion is when a player becomes aware that they are hearing the same looped ambience repeated multiple times with no variation. Using the previous example, exclusively using only looped ambience in a game will quickly become repetitive and will either attract the attention of the player to the audio in a negative way or cause them to subconsciously start ignoring the audio. Both of these outcomes will ultimately detract from their enjoyment and immersion in the game.

OneShotAudioRandomLocation

This script uses a number of similar functions for random volume, pitch, and alternate AudioClips, as described in the RandomAudioPlayer script featured in the existing game mechanics.

The OneShotAudioRandomLocation script also adds in two new features that are very well suited to creating and maintaining an immersive ambience.

Random Play Delay Time

Random location to play from

The OneShotAudioRandomLocation script will modify the AudioSource Component, choosing random values within the range you set every time the audio is triggered to play and thus drastically reducing the player listening fatigue from repetition.

Figure 13.1.13 OneShotAudioRandomLocation Script as Displayed in Inspector

This script functions much like the RandomAudioPlayer script, with several important additions.

First, it enables you to set up random delay times before the AudioSource will pick a new AudioClip and play again. These times are set by the Min and Max Time To Wait parameters in seconds.

Second, it enables you to create a number of Empty GameObjects to use as alternate locations. Every time the audio plays, it will select a new random location from the Array or Bank of Alternate Empty GameObjects in the Alt Transform variable.

This script is very well suited for playing singular One Shot ambience sounds that you want to play from different locations in the gameworld. Doing this ensures that the player will not find your placed 3D ambience repetitive, as it will play from a different location using a random AudioClip, random volume, and random pitch. It is intended to be used alongside and to compliment 2D and 3D looped ambience as an additional detail layer.

THIS SCRIPT SHOULD NOT BE USED FOR LOOPING SOUND ASSETS. It has been written to play singular One Shot Audio Assets, and therefore adding in a looping sound may not have the behaviour you desire.

Min and Max Time

The Min Time and Max Time Variables will allow you to choose a minimum and maximum time in seconds for the script to wait before selecting and playing a new One Shot AudioClip will randomly pick a value between the Minimum and Maximum Time ranges before then playing the AudioSource.

If you do not want to apply any random delay time to an AudioSource you can enter the Min Time To Wait and Max Time To Wait to the same value as you would with Min and Max Pitch and volume on the RandomAudioPlayer script. For example, if you decided to implement the sound to play no more frequently than every 10 seconds, but to wait no longer than every 30 seconds, you would ensure you enter the value 10 in the Min Time parameter and 30 in the Max Time parameter.

Tip

DO NOT attempt to use the Play On Awake or Loop functions on the AudioSource. The code in this script has been specifically written to make the AudioSource begin to play when the random timer has reached the desired number, and to swap out the AudioClip every time it is retriggered. Some additional code has been included within this script to ensure that the Play On Awake and Loop parameters of the AudioSource will be automatically disabled/deactivated when beginning to play the game, or when Enabling the GameObject containing the OneShotAudioRandomLocation script.

Alt Transforms

The Alt Transforms variables allow you to add in a number of Empty GameObjects to select a random set of Transform values. This lets your sounds move around the level and can greatly help alleviate listener fatigue when used appropriately with ambient sounds. Playing back sounds in the same location, such as crickets or birds, can quickly become repetitive. You are able to use this script to place a number of points around the level that these sounds could potentially play from, so that the sound is much less repetitive than if it continually played from a fixed location. If you do not add in any alternate Transform GameObjects, the AudioSource will remain in the location it is placed.

Tip

Set appropriate Minimum and Maximum Distance and Volume parameters, as the sound could potentially play back much louder than intended if the player is standing directly on top of the location the sound is playing from.

An example using this script has been added to the With Audio project in Level01.

It can be found using the following Hierarchy path:

(Level 01 Scene) Audio > Ambience SFX > Ambience One Shot Swamp Creatures

AudioTriggerMultiColliders

The AudioTriggerMultiColliders script is similar to the InteractOnTrigger script but with one significant modification. Using traditional Trigger Area setup as described in Chapter 7, I stated that you needed to ensure that, when controlling a single GameObject using a pair of Trigger Area Colliders, these Colliders cannot touch or be placed alongside each other (such as the example in Level01 for the Audio Reverb Zones). When using the standard InteractOnTrigger script this is still true; however, the AudioTriggerMultiColliders script has been specifically modified to allow you to create as many Trigger Areas as you require that overlap one another. This will allow you to link a number of overlapping Colliders using Child GameObjects to create more complex shapes.

The InteractOnTrigger script can be used very effectively to Enable/Disable or change parameters on GameObjects containing ambience, music, or dialogue in areas that have a very clear entry/exit point. The major disadvantage of using code Script is that it is not very well suited if you want to draw a complex Trigger Area inside of an irregularly shaped room or game section with no clear entrance or exit.

In the same Project Panel folder as the previous Additional Audio scripts, you will find an additional folder named Audio Triggers containing an AudioTriggerMultiColliders script:

Assets > 3DGameKit > Scripts > Additional Audio Scripts > AudioTriggerMultiColliders

Figure 13.1.14 AudioTriggerMultiColliders Script as Displayed in Inspector

To set up script, you will be required to:

Create a New Empty GameObject

Name this GameObject appropriately

Add a Collider Component such as Sphere Collider or Box Collider

Set the Collider to Is Trigger

Move and resize the GameObject to the required location

Add the AudioTriggerMultiColliders script

Set the Layers parameter (presumably to Player)

Assign the GameObject you want to modify to the On Enter () or On Exit () variable/s

Assign the particular function you want to happen when entering any of the Trigger Areas or exiting the final Trigger Area

Press the Add Child Collider button if you require an additional Trigger Area to more accurately model a complex shaped room or space (this script has been specifically coded to ensure there will not be any issues if multiple Colliders overlap one another)

Move and resize the Collider Component in the new Child Trigger GameObject to the required location

Ensure all the Trigger Area Layers for each GameObject have been set to Collider (this should be set automatically by the code within the script)

Figure 13.1.15 AudioTriggerMultiColliders Example

Improving on existing Audio Implementation

This section will look at how to improve upon the initial Audio Implementation in the Silent 3D GameKit Project for the following game mechanics:

Adding SFX to Ellen’s Shield Mechanic

Adding SFX for Ellen’s Respawn Mechanic

Adding Additional Ambient SFX to the Staff weapon on the Podium

Adding Start and Stop SFX for the Rising Platforms

Adding SFX when Ellen loses a Health Point or Regains Health

Adding SFX when Ellen’s Health Points are low

Adding SFX to the Dialogue UI Animations

Adding SFX to Chomper and Spitter Death Particles

Ellen’s shield

When Ellen is damaged, you will see a pulsing, blue-coloured visual effect. This is to show she has been damaged and is now invulnerable for a few seconds. I would imagine this mechanic was added by the original Game Developers to ensure that Ellen couldn’t be swarmed by a gang of Chompers and immediately killed. For the purposes of maintaining the narrative of the game, we could say this effect is due to some kind of forcefield or shield activating.

Figure 13.2.1 Ellen Blue Shield Visuals in Game View

You can add a SFX to play when this blue shield visual effect is visible by using the existing game mechanics’ Hierarchy structure. The GameObject Ellen_Shield becomes Enabled for the visuals for this mechanic; it gets Disabled after a few seconds, allowing Ellen to become vulnerable again.

This can be found using the following Hierarchy path:

Ellen > Ellen_Shield

You could simply create a Looping Audio Asset and add in an AudioSource GameObject as a Child of the Ellen_Shield Parent GameObject. Set this AudioSource to Play On Awake and let the existing Damageable script on the Parent Ellen GameObject Enable the Ellen_Shield GameObject whenever she is damaged by an enemy. However, when the shield visual effect wears off and is Disabled after a few seconds, the AudioSource will also immediately stop playing as the Parent Ellen_Shield GameObject is Disabled; this will not sound very immersive for the player.

This mechanic would feel considerably more fluid if the Audio Asset was created as a One Shot instead, and if the audio file was timed in length to feature a volume fade out within the audio file, just after the visual effect vanished from the game. This small change in the sound design and implementation will have a noticeable effect on how the player perceives the game mechanic. The audio will smoothly fade out just after the effect ends, instead of just immediately and abruptly cutting off and stopping alongside it.

The method outlined subsequently will walk you through how to set up an AudioSource GameObject to be Enabled from the Ellen_Shield GameObject, using some of the Additional Audio Scripts outlined earlier without resorting to placing the AudioSource directly as a Child GameObject of Ellen_Shield. If you make your SFX for this effect slightly longer than the visuals with a gentle fade out in volume within the Audio Asset, this mechanic will feel a lot smoother to the player because the audio has been implemented in a symbiotic, sympathetic way to reinforce the visuals.

Begin by adding in an AudioSource GameObject as a Child of the Ellen Parent GameObject

Ensure the Transform values of the new GameObject have been reset to 0 for Position and Rotation

Rename this to EllenShieldAudio (or a similar name of your own choosing)

Add in the AudioClip you want to use for this

Set your Spatial Blend settings to either 2D or 3D

Ensure that the Play On Awake function is Activated/Enabled

Finally, ensure that the EllenShieldAudio AudioSource GameObject is Disabled when starting the level

Select the Ellen_Shield GameObject in the Hierarchy

Add in the AudioEnableGameObject script using the Add Component button in the Inspector

Assign the EllenShieldAudio AudioSource GameObject to the GameObject to Enable Variable

Figure 13.2.2 Adding AudioEnableGameObject Script to Ellen_Shield GameObject and Assigning AudioSource

The existing code in the game for the mechanic will activate the Ellen_Shield GameObject when Ellen is damaged by an enemy. If you play the game at this point, you will hear that the Shield SFX will work but only the first time Ellen is injured and the Shield visual effect appears on screen. If she is injured a second, third, or even fourth time, the sound for the shield will not play. This is because the EllenShieldAudio AudioSource GameObject has been Enabled the first time she is damaged by the AudioEnableGameObject script on the Ellen_Shield GameObject. The subsequent times Ellen is injured and the Shield appears, the AudioEnableGameObject script will tell the EllenShieldAudio to Enable, but since the EllenShieldAudio AudioSource GameObject is already Enabled, Play On Awake is unable to play the AudioClip Asset again.

To solve this issue, follow the remaining steps to add in the DisableAfterFinishPlaying script. This DisableAfterFinishPlaying script will Disable the EllenShieldAudio AudioSource GameObject, after the AudioClip Asset has finished playing. This will allow the AudioSource GameObject to be Enabled again the subsequent times Ellen is injured and continue using the Play On Awake parameter to trigger the audio to play each and every time it is Enabled.

Select the EllenShieldAudio AudioSource GameObject in the Hierarchy

Add in the DisableAfterFinishPlaying script using the Add Component button in the Inspector

Assign the EllenShieldAudio AudioSource GameObject to the Disable AudioSource After Play Variable

Figure 13.2.3 EllenShieldAudio AudioSource Parameters and AudioDisableAfterFinishPlaying Script

Ellen respawn

When Ellen respawns, you will see a particle-based visual effect lasting a few seconds. This should be created as a singular One Shot Audio Asset or, ideally, as multiple variations of One Shot Audio Assets.

Figure 13.2.4 Ellen Respawn Visuals in Game View

The Damageable script on the Parent Ellen GameObject will set in motion events killing the playable character Ellen and respawning her at the nearest checkpoint when her health bar has zero hearts remaining. This existing code will also Enable, then Disable the RespawnParticles GameObject when the effect has finished.

This can be found using the following Hierarchy path:

Ellen > RespawnParticles

Like the previous Shield mechanics, this Respawn mechanic would feel considerably more fluid if the sound began fading down in volume within the audio file just after the visual effect vanished, instead of just immediately and abruptly cutting off and stopping alongside it. Please take this into consideration when designing your One Shot Audio Assets for the Respawn mechanic.

The following steps outline how to implement a sound to correspond with the Respawn mechanic:

Begin by adding in an AudioSource as a new Child GameObject located within the Ellen Parent GameObject

Ensure the Transform values of the new GameObject have been reset to 0 for Position and Rotation.

Rename this to EllenRespawnAudio (or a similar name of your own choosing)

Using the Add Components button add in a RandomAudioPlayer script Component

Add in the AudioClip/s you want to use for this to the RandomAudioPlayer Component

Set your Spatial Blend settings to either 2D or 3D

Ensure that the Play On Awake and Loop functions are Unchecked/Deactivated

Ensure that the EllenRespawnAudio AudioSource GameObject is Enabled when starting the level

Select the RespawnParticles GameObject in the Hierarchy and add in a New Empty GameObject as a Child of the RespawnParticles GameObject

Rename this to AudioTriggerRandomAudioPlayer (or a similar name of your own choosing)

Using the Add Components button in the Inspector to add in an AudioPlayRandomAudioPlayerScript script Component to the AudioTriggerRandomAudioPlayer GameObject

Assign the EllenRespawnAudio RandomAudioPlayer AudioSource GameObject to the Random Audio Player GameObject Variable.

Figure 13.2.5 Added AudioTriggerRandomAudioPlayer GameObject with AudioPlayRandomAudioPlayer Script and Assigned AudioSource GameObject

The AudioPlayRandomAudioPlayerScript will play the EllenRespawnAudio AudioSource GameObject containing the RandomAudioPlayer script, allowing you to add in as many AudioClip variations as you want along with the Random Volume, Pitch, and, if needed, Play Delay functions.

The AudioTriggerRandomPlayer GameObject contains the AudioPlayRandomAudioPlayerScript and will activate this automatically as it is a Child of the RespawnParticles GameObject. When the code in the game Enables the RespawnParticles GameObject to trigger the visual effects, your audio will also play alongside this. As your EllenRespawnAudio AudioSource GameObject is not directly a Child of the RespawnParticles GameObject, this will allow you to make your AudioClip Assets slightly longer in length than this visual effect. This should allow you to have a smooth fade out/transition with the aim of immersing the player further in the game while hopefully not drawing their attention to the visual effect suddenly cutting out after a few seconds.

Staff Podium

You may want to add in an additional SFX to the Podium near the start location in Level01 where the player can find the Staff weapon. After the playable character has entered the Trigger Area surrounding the staff, it will vanish from the game and the player will be able to use the weapon. You have already learned how to add in a One Shot SFX corresponding with the staff being collected.

You could also add in an additional Seamless Looping sound that could be used to help guide the player to the Staff in a similar way to the Crystals that also need to be collected. Another option for this sound could be as a Seamless Looping ambience that will play when the playable character is close to the Podium, as if the Staff itself were pulsing with powerful or magical energy.

Figure 13.2.6 Staff Weapon Podium in Level01 Game View

The WeaponPedestal GameObject is used for the GameObjects associated with this mechanic.

This can be found using the following Hierarchy path:

(Level01 Scene) Level01Gameplay > WeaponPedestal

Begin by adding in a new AudioSource GameObject as a Child of the Parent WeaponPedestal GameObject

Rename this to WeaponPedestalAudioLoop (or a similar name of your own choosing)

Position this over the Staff Weapon Podium

Add in the AudioClip you want to use for this

Set your Spatial Blend settings to 3D

Set the Min and Max Distance parameters depending on how far away you want this player to be able to hear this sound

Ensure that the Play On Awake and Loop functions are Activated

Finally ensure that the WeaponPedestalAudioLoop AudioSource GameObject is Enabled

Figure 13.2.7 Staff Podium Before Collected AudioSource Settings

Presumably, you want this sound to begin playing automatically when the player begins the level. The existing InteractOnTrigger script already used for the Collect Staff SFX can be used to then Stop this new AudioSource when the Staff has been successfully collected.

Select the StaffTakeTrigger GameObject using the following Hierarchy path and observe the InteractOnTrigger script Component in the Inspector.

(Level01 Scene) Level01Gameplay > WeaponPedestal > StaffTakeTrigger

Add in a new variable on the On Enter () function of the InteractOnTrigger Component by left clicking on the + symbol at the bottom right-hand corner of the On Enter () event

Assign the WeaponPedestalAudioLoop AudioSource GameObject to the new variable

Set the function to AudioSource.Stop

Rising platforms

There are a number of moving platforms the player must use to traverse the acid hazards in Level02.

Figure 13.2.8 Moving Platforms Model

You can add in One Shot start and stop SFX to the platforms as the begin or end travelling up and down to compliment the Seamless Looping sound you have already integrated within the mechanic.

Locate the GameObjects for the first platform that rises using the following Hierarchy path:

Level02Gameplay > MovingPlatforms > RisingPlatform1 > Triggers Areas > TriggerAreaTop

Level02Gameplay > MovingPlatforms > RisingPlatform1 > Trigger Areas > TriggerAreaBottom

Level02Gameplay > MovingPlatforms > RisingPlatform1 > Body > AdditionalAudioCollider

These TriggerAreaTop, TriggerAreaBottom, and AdditionalAudioCollider GameObjects have been created specifically for this mechanic.

If you select the Parent RisingPlatform1 GameObject, you will see a Box Collider surrounding the main Platform GameObject. You will also see two very thin Box Colliders positioned above and just below the Rising Platform. With the RisingPlatform1 GameObject still selected in the Hierarchy, use the Inspector to find the SimpleTranslator script Component. Now adjust the Preview Position slider left and right to see how this platform will move up and down. Observe that the Box Collider surrounding the main Platform GameObject will enter and leave the Top and Bottom Colliders.

You will now add in an InteractOnTrigger script to play a Start and Stop SFX when the Collider surrounding the main platform enters and exits these Top and Bottom Trigger Areas.

If you select the AdditionalAudioCollider GameObject in the Hierarchy, you will see at the top of the Inspector that this has been set to the Vehicles Layer. It has been set to this not by mistake and not because it is a vehicle, but to ensure that when you set a corresponding Layer in the InteractOnTrigger script, that you can be sure that any GameObjects assigned to the Player, Enemy, or Environment Layer will NOT be able to trigger the start or stop SFX to play. The reason the Vehicles Layer was chosen is because there are no nearby GameObjects assigned to this Vehicles Layer that could possibly accidentally activate the On Enter () or On Exit () functions of the InteractOnTrigger script.

Warning

This Audio Implementation method is not strictly best practice and would be considered something of a hack, but in professional Game Development sometimes you have to creatively use the tools you have to get the job done.

Begin by creating two AudioSources as Child GameObjects of the RisingPlatform1 > Body Child GameObject.

Figure 13.2.9 Rising Platform Hierarchy with Added Start and End Audio GameObjects

Name one of these AudioSources RisingPlatformStartAudio and the other RisingPlatformEndAudio.

Add a RandomAudioPlayer Component to each of the RisingPlatformStartAudio and RisingPlatformEndAudio AudioSource GameObjects. Set your Spatial Blend parameter to 3D so the start and stop sounds playback diegetically from the location of the platform. Check the Position and Rotation Transform values are all set to 0 for the RisingPlatformStartAudio and RisingPlatformEndAudio AudioSource GameObjects.

As explained in Chapter 10, when first adding in a looping sound for this mechanic, it is important to ensure the sound will pan in Unity from the centre of the platform Body Child GameObject as it moves up and down. Ensuring the Transform Position locations are set to default values (X = 0, Y = 0, Z = 0) will mean the AudioSource will be located in the middle of the Platform.

Next, select the PlatformTriggerAreaTop GameObject in the Hierarchy

Add in an InteractOnTrigger script Component

Set the Layers parameter to Vehicles so that it triggers when the AdditionalAudioCollider GameObject passes through the Box Collider on the PlatformTriggerAreaTop

Click the + button on the On Enter () function to add in a new variable

Assign the RisingPlatformEndAudio GameObject containing the RandomAudioPlayer and AudioSource Components to the On Enter () variable

Set the Function to use the PlayRandomClip command on the RandomAudioPlayer

Click the + button on the On Exit () function to add in a new variable

Assign the RisingPlatformStartAudio GameObject containing the GameObjectRandomAudioPlayer and AudioSource Components to the On Enter () variable

Set the Function to use the PlayRandomClip command on the RandomAudioPlayer

Figure 13.2.10 Assigning RisingPlatformEnd GameObject to On Enter () Event Set to RandomAudioPlayer PlayRandomClip () Function

This command will tell the RandomAudioPlayer to select a Random AudioClip, Random Pitch, and Random Volume based upon the settings used for the RisingPlatformEnd GameObject in the Inspector.

Next, select the PlatformTriggerAreaBottom GameObject in the Hierarchy

Add in an InteractOnTrigger script Component

Set the Layers parameter to Vehicles

Click the + button on the On Enter () function to add in a new variable

Assign the RisingPlatformEndAudio GameObject containing the RandomAudioPlayer and AudioSource Components to the On Enter () variable

Set the Function to use the PlayRandomClip command on the RandomAudioPlayer

Click the + button on the On Exit () function to add in a new variable

Assign the RisingPlatformStartAudio GameObject containing the GameObjectRandomAudioPlayer and AudioSource Components to the On Enter () variable

Set the Function to use the PlayRandomClip command on the RandomAudioPlayer

Figure 13.2.11 PlatformTriggerAreaBottom GameObject with InteractOnTrigger script featuring Assigned RisingPlatformEnd and RisingPlatformStart GameObjects

If you play the game at this point, walk through the first moving door and into the room featuring the first Rising Platform. You should now hear your start and stop sounds as the platform moves up and down.

You may find that you need to set the Min and Max Distances on the AudioSource to quite a large radius to sound correct in the room, but that these sounds are coming through the walls into the adjoining rooms. If this happens, consider setting up additional Trigger Areas on the entrances and exits of the room to Enable and Disable GameObjects containing the MuteAudioSource and UnMuteAudioSource Script Components.

The remaining RisingPlatform GameObjects in Level02 all use this exact same set up; you will need to locate these using the Hierarchy path and perform the previous steps on all three rising platforms individually.

(Level02 Scene) Level02Gameplay > MovingPlatforms > RisingPlatform1

(Level02 Scene) Level02Gameplay > MovingPlatforms > RisingPlatform2

(Level02 Scene) Level02Gameplay > MovingPlatforms > RisingPlatform3

Chomper and Spitter vanish SFX

When the player kills the Chomper and Spitter enemies, after a few seconds a particle effect will appear as the enemies vanish from the Scene. I presume this has been a design choice the Game Developers made to make the game more appealing to a younger audience, choosing to make the enemies evaporate or vanish so you don’t see lots of dead enemies littering the level.

Figure 13.2.12 Dead ChomperRagdoll Model

When the Chomper and Spitter enemies are killed, Unity has been set up to instantly switch from a Prefab of the enemy that is able to attack the player, to one with no abilities. Unity does this by removing the Chomper Enemy GameObject from the Hierarchy and spawning in a ‘dead’ Chomper Prefab containing the script and variables required to add in the vanish One Shot SFX.

Select the Parent Prefab GameObject for any of the Chomper enemies in the Hierarchy for either the Level01 or Level02 Scenes

Observe the ReplaceWithRagdoll script Component in the Inspector

Ensure the Project Panel is visible and unlocked, then left click on the DeadChomperRagdoll Prefab assigned to the Ragdoll Prefab variable

This will now highlight the location of the DeadChomperRagdoll Prefab in the Project Panel

Alternatively, directly select the DeadChomperRagdoll Prefab using the following Project Assets path:

Project Panel Asset path:

Assets > 3DGameKit > Prefabs > Characters > Enemies > Chomper > DeadChomperRagdoll

Double left click on the ChomperRagdoll Prefab in the Project Panel to open the Prefab up in Prefab Editing Mode

Select the Parent ChomperRagdoll GameObject in the Hierarchy

Observe the VanishAudio variable on the Vanish script

Create a new AudioSource GameObject as a Child of the Body GameObject and add a RandomAudioPlayer script Component

Figure 13.2.13 Dead ChomperRagdoll Prefab Hierarchy

Your new Audio GameObject MUST be placed as a Child of the Body Child GameObject.

Placing this on the root of the Hierarchy will cause an error within the existing code and cause the Chompers to become invincible!

Name this AudioSource GameObject VanishAudio or a similar name of your own choosing

Ensure the Transform values of the new GameObject have been reset to 0 for Position and Rotation

Add in your AudioClip Assets and set Min/Max parameters

Ensure the AudioSource Component is NOT using Play On Awake or Loop

Set the Spatial Blend parameter to 3D and adjust the Min and Max Distance

Finally, assign the VanishAudio RandomAudioPlayer AudioSource GameObject to the Vanish Random Audio Variable on the Vanish script

Exit Prefab Editing Mode ensuring you have saved your changes

Figure 13.2.14 DeadChomperRagdoll GameObject with Vanish Script and Vanish Random Audio Variable

You can follow these steps to also add in a Vanish sound for the Spitter enemy following the same instructions as the Chomper. Add in your GameObject containing a RandomAudio Player and AudioSource Component as a Child of the SpitterMesh GameObject within the DeadSpitterRagdoll Prefab.

Figure 13.2.15 DeadChomperRagdoll Prefab Hierarchy with VanishAudio GameObject Added

Select the DeadSpitterRagdoll Prefab using the following Project Assets path:

Assets > 3DGameKit > Prefabs > Characters > Enemies > Chomper > DeadChomperRagdoll

Chomper and Spitter additional Collision sounds

If you have just added in the vanish sounds when the enemies evaporate into the air, you may also have just noticed that there are no SFX when the DeadChomperRagdoll Prefab impacts off the floor after being struck by Ellen’s Staff weapon.

You are able to add a One Shot sound to complete the full audio experience from the defeated Chomper and Spitter enemies by following the next steps.

Select the DeadChomperRagdoll Prefab using the following Project Assets path:

Assets > 3D GameKit > Prefabs > Characters > Enemies > Chomper > DeadChomperRagdoll

Double left click on the DeadChomperRagdoll Prefab in the Project Panel to open the Prefab up in Prefab Editing Mode

Create a new AudioSource GameObject as a Child of the DeadChomperRagdollCollision and add in a RandomPlayScript Component

Ensure the Transform values of the new GameObject have been reset to 0 for Position and Rotation

Name this AudioSource GameObject CollisionHitAudio or a similar name of your own choosing

Your new Audio GameObject MUST be placed as a Child of the Body Child GameObject.

Placing this on the root of the Hierarchy will cause an error within the existing code and cause the Chompers to become invulnerable!

Add in your AudioClip Assets and set Min/Max parameters

Ensure the AudioSource Component is NOT using Play On Awake or Loop

Set the Spatial Blend parameter to 3D and adjust the Min and Max Distance

Select the DeadChomperRagdollCollision GameObject in the Hierarchy

Add in an InteractOnTrigger script and set the Layers parameter to Everything

Click on the + button to add in a new variable for the On Enter () event

Assign the CollisionHitAudio GameObject to this new On Enter () variable

Set the PlayRandomClip Function on the On Enter () variable

Finally, Exit Prefab Editing Mode ensuring you have saved your changes

Figure 13.2.16 DeadChomperRagdollCollision GameObject with Added InteractOnTrigger Script

The reason the InteractOnTrigger Layers parameter is set to Everything is so that no matter what the Chomper enemy gets knocked back or collides into, a collision bodyfall type SFX will play.

You can follow the earlier steps to also add in a Collision sound for the Spitter enemy by using the following Project Panel Assets path:

Select the DeadSpitterRagdoll Prefab using the following Project Assets path:

Assets > 3DGameKit > Prefabs > Characters > Enemies > Chomper > DeadSpitterRagdoll

Like the Vanish SFX for the Spitter, the DeadSpitterRagdollCollision GameObject can be found as a Child of the SpitterMesh GameObject.

Level02 spaceship One Shot arrival

In Chapter 10, you added in a looping sound for the spaceship featured at the end of Level02.

We will now revisit this mechanic and add in a One Shot sound to play when the spaceship arrives and lands. This will allow you to create a much more detailed sound specific to the beginning part of this animation.

Locate the Dropship GameObject in the Hierarchy in Level02

Create a new AudioSource as a Child of the Dropship GameObject

Add your One Shot Audio Asset to the AudioClip parameter

Set the AudioSource GameObject to be Enabled

Set the Play On Awake parameters on the AudioSource to be Enabled

Set the AudioSource Spatial Blend and Min/Max Distance settings you think are appropriate

Next, go to the Audio Mixer Panel and create an Audio Mixer Group for the Arrival AudioSource and another for the Idle/Ground Loop AudioSource. Route the AudioSource Output to each respective Audio Mixer Group.

Add in a Duck Volume Effect to the Idle Looping Audio Mixer Group and create a send effect on the Arrival Audio Mixer Group. Route the output of this send from the Arrival to the Idle Loop Audio Mixer Group and turn the level of this up fully.

Figure 13.2.17 Audio Mixer Routing Between Arrival and Idle DropShip Audio Mixer Groups

Finally, select the Duck Volume Effect and set this to fully duck out or silence the Loop Mixer Group when the One Shot arrival sound is playing.

Figure 13.2.18 DropShip Idle Audio Mixer Group with Duck Volume Effect

In effect, what’s now happening is that the Loop AudioSource does still begin to play when the Dropship GameObject is activated, but the One Shot arrival sound is ducking or effectively turning down the volume of this. When the One Shot sound ends and no more signal is passing through the send, the Loop sound will now play at full volume.

To help match the sound between the end of the One Shot sound and the beginning of the Loop, with the aim of making this transition as seamless as possible, try setting both AudioSources to use the same Min/Max Distances, and also attempt to match the volume of the end of the One Shot with the Loop. This will really help match the exchange when the One Shot sound ends and the Loop begins.

UI health bar animations

Ellen has a health bar found in the top left of the screen when playing the game. This works much like the majority of health bars found in games; when she is attacked or injured by an enemy, she will lose a heart. When she has lost all five of her hearts, she will die and respawn at the closest checkpoint.

Figure 13.3.1 UI Health Bar Heart Icons

In the silent version of the 3D GameKit that has been provided to you, there is currently no way of playing additional sounds when Ellen gains or loses a heart without adding the Audio Implementation yourself. The following steps will show you how to do this using the toolkit you have been provided.

UI health – losing a heart

You can add in a One Shot SFX to play whenever Ellen loses a heart to correspond with the animation and to give the player some aural feedback.

To add in a SFX when Ellen is injured and loses a heart, you first need to create an AudioSource. You will add this as a Child of the Ellen Prefab

Figure 13.3.2 TakeDamageUIAudio AudioSource GameObject Parameters

To play this AudioSource at the correct time observe the Damageable script found on the Parent Ellen GameObject

Click on the small + symbol at the bottom right-hand corner of the On Death () and On Receive Damage () Event Components

This will add in a dropbox for each as in Figure 13.3.3

Figure 13.3.3 Ellen Parent GameObject Adding Variables for On Death () and On Receive Damage () Events

Next, you need to drag and drop your AudioSource GameObject to assign it onto the two new variable drop target variables

Figure 13.3.4 Assigned AudioSource GameObjects into Variables

If you then left click where it currently reads No Function, you can select what you want to happen when the Death or Receive Damage events happen in the game. You should change these to GameObject > Set Active Bool ().

As you can see in Figure 13.3.5, the On Receive Damage () Event displaying No Function has been replaced with GameObject.SetActive and a checkbox has appeared. If this checkbox is Enabled, then the GameObject assigned to the Variable will be Enabled when this event happens in the game.

Figure 13.3.5 Setting Variable Functions to GameObject SetActive (bool)

You will now need to prepare the AudioSource to play when it has been Enabled by these Events.

When selecting the AudioSource in the Hierarchy, check that you have applied appropriate Spatial Blend settings. You also need to Activate Play On Awake and check that the GameObject itself has been Disabled so that it doesn’t immediately start playing as soon as the game begins.

If you playtest the game at this point, you will notice that the SFX for the UI, when an enemy injures the playable character, will trigger the SFX correctly the first time the player loses health, but will NOT trigger a second time the player is injured and the heart removal animation is shown. You need to add in an AudioDisableAfterFinishPlaying script to the AudioSource so that the GameObject will Disable itself automatically when the AudioClip has finished playing. The AudioSource will then be Disabled and ready to play again the next time the receive Damage or Death Event happens.

Figure 13.3.6 AudioSource GameObjects Disabled by Default with Audio DisableAfterFinishPlaying Script Added and Assigned to AudioSource Component Above

UI health – restoring hearts

You can add in a One Shot SFX to play whenever Ellen recovers health, to correspond with the animation and to give the player some aural feedback.

This sound can trigger when Ellen smashes one of the health recovery Stone Chests, or when respawning after death.

To add in a One Shot SFX, you first need to create an AudioSource. You will add this as a Child of the Ellen Prefab

Figure 13.3.7 GainHealthUIAudio AudioSource GameObject Parameters

To play this AudioSource at the correct time, you will need to look at the Damageable script found on the Parent Ellen GameObject

Click on the small + symbol at the bottom right-hand corner of the On Reset Damage () Event Component

This will add in a dropbox to attach the AudioSource

Figure 13.3.8 Ellen Parent GameObject Adding Variables for On Reset Damage () Event

Next, you need to drag and drop the AudioSource GameObject you have created onto the new variable drop targets.

If you then left click where it currently reads No Function, you can select what you want to happen when the On Reset Damage Event happens in the game.

You should change these to GameObject > Set Active Bool ().

Figure 13.3.9 Assigned GainHealthUIAudio AudioSource GameObject Into On Reset Damage () Variable and Set to GameObject.SetActive Function

As you can see in Figure 13.3.9, On Receive Damage () Event, the No Function parameter has been replaced with GameObject.SetActive and a checkbox has appeared. If this checkbox is Enabled, then the attached GameObject will be activated when this Event happens in the game, i.e. when the player respawns or recovers health from a Stone Chest.

You will now need to prepare the AudioSource to play the attached AudioClip when it has been enabled by these Events. If you select the AudioSource you created for the restoring health UI animation, you will want to ensure that appropriate 2D and Stereo Pan spatial settings have been applied. You also need to ensure Play On Awake has been Activated, and that the GameObject itself has been Disabled so that it doesn’t immediately start playing as soon as the game begins.

If you play the game at this point, you will notice that the SFX for the UI when Ellen regains health will trigger as soon as the level starts. This is because the code within the game has been setup to play this sound when her damage has been reset using the On Reset Damage () Event.

We cannot remove this GameObject from this Function, but we can make sure it is not audible at the start of the level. There are multiple ways to solve this problem. One method is by adding in an AudioCountdownEnableObject script assigned to Enable a GameObject containing an UnMuteAudioSource Script. You would set the Health Gain GameObject AudioSource to be muted when beginning the level; next, assign this AudioSource GameObject to the UnMuteAudioSource Script which could be activated using an AudioCountdownEnable after 2 or 3 seconds. This should be assigned to unmute the AudioSource, allowing it to now be heard as intended for the remainder of the level.

Figure 13.3.10 Creating GameObject with AudioCountdownEnableObject Script Assigned to UnMuteGainHealthAudioSource GameObject

Figure 13.3.11 UnMuteGainHealthAudioSource GameObject Disabled by Default with UnMuteAudioSource Script Assigned to GainHealthUIAudio AudioSource

Like the previous UI Losing heart example, you will also notice that this sound will play correctly the first time Ellen regains health, but will NOT trigger or play the second time she opens a HealthChest in the game. To solve this issue, you need to add in an AudioDisableAfterFinishPlaying script to the AudioSource. This will ensure that the GameObject will Disable itself automatically when the AudioClip has finished playing. This will make sure that the AudioSource is Disabled and ready to be Activated/Enabled and play again the next time the On Reset Damage () Event happens.

Figure 13.3.12 GainHealthUIAudio AudioSource Parameter Settings with AudioDisableAfterFinishPlaying Script

UI health – playing a SFX when Ellen’s health reaches critical level

It is also possible to add in implementation to play an AudioSource when Ellen’s health reaches a critically low level. You could choose to play a Seamless Looping heartbeat type SFX, or some other audio element to make the player more aware that their health is critically low, and increase the tension in the game.

Begin by adding in an AudioSource GameObject as a Child of the Ellen Parent GameObject

Rename this to EllenLowHealthAudio (or a similar name of your own choosing)

Activate the Play On Awake and Loop function in the EllenLowHealthAudio and add in your AudioClip

Add in a AudioSource FadeInVolume Script and assign this to the EllenLowHealthAudio AudioSource

Figure 13.3.13 EllenLowHealthAudio AudioSource GameObject Parameter Settings

Select the Parent Ellen GameObject in the Hierarchy

Using the Add Components button, add in a DamageableEnableGameObject Script Component to the Parent Ellen GameObject

Assign the Parent Ellen GameObject to the Assign GameObject Containing Damageable Component Variable

Change the Enable When Health Remaining At Variable from 0 to 1 (or whatever value you want to use between 1 and 4)

Assign the EllenLowHealthAudio AudioSource GameObject to the GameObject to Enable Variable

Figure 13.3.14 Adding DamageableEnableGameObject Script to Parent Ellen GameObject and Assigning Parent Ellen GameObject to First Variable and EllenLowHealthAudio GameObject to Third Variable

As the variable name suggests, you can only assign a GameObject containing a Damageable script Component to the Assign GameObject Containing Damageable Component Variable. The code within this script needs to be able to access Ellen’s current health points set within the Damageable Script to know if the EllenLowHealthAudio AudioSource GameObject should be Enabled or Disabled.

The DamageableEnableGameObject Script will Enable the EllenLowHealthAudio AudioSource GameObject when Ellen’s health is at the same value as that entered in the Enable When Health Remaining At Variable. As the EllenLowHealthAudio AudioSource has been set to Play On Awake, this sound will play when the EllenLowHealthAudio GameObject has been Enabled.

It is up to you to decide if this should only happen when Ellen only has a single health point remaining, or if this sound should potentially be more subtle and begin when she has slightly more health? Another option is up to you to decide if this should be a 3D or 2D sound, and also if this should be a Looping sound such as a heartbeat or if this should be a single One Shot Audio Asset more like a notification.

This is a creative decision and there are technically no right or wrong answers; it is up to you to decide how this audio mechanic should work within your game.

UI subtitle animations

You have previously learned how to implement speech alongside the UI subtitle animations.

You will now learn how to add in UI SFX to correspond with the subtitles appearing and disappearing animations.

Figure 13.4.1 Subtitle Example in Scene View

In the version of the Silent 3D Gamekit that has been provided to you, there is currently no way of playing additional sounds to accompany this animation without adding the Audio Implementation yourself.

UI subtitles – appear/open animation

You can add in a One Shot SFX to play whenever the subtitles appear to correspond with the animation and to give the player some aural feedback.

Begin by creating an AudioSource as a Child of the Level01InformationZones GameObject

Add in the AudioClip you want to use for this

Set your Spatial Blend settings and ensure that Play On Awake is Activated and that the AudioSource is Disabled

Finally, add in the AudioDisableAfterFinishPlaying Script and assign this to the AudioSource

Figure 13.4.2 Creating SubtitleAppearUIAudio AudioSource GameObject Disabled as Default, Activating PlayOnAwake AudioSource Parameter, and Adding AudioDisableAfterFinishPlaying Component

Select one of the InfoZone GameObjects; in this example I will choose InfoZone02.

Click on the small + symbol at the bottom right-hand corner of the On Enter () Event Component

Attach the AudioSource into this variable/drop target and set this to GameObject.SetActive

Finally, ensure the checkbox is Activated so this GameObject will use Play On Awake to play the AudioClip when the On Enter () event occurs

Figure 13.4.3 Adding Variable for On Enter () Event on InfoZone GameObjects Setting Function to GameObject.SetActivate and Assigning SubtitleAppearUIAudio GameObject

Playtest the game to check that the AudioSource is playing as intended when entering the Sphere Collider Trigger Area Component connected to the InfoZone02 GameObject.

UI subtitles – disappear/close animation

You can add in a One Shot SFX to play whenever the subtitles disappear, to correspond with the animation and to give the player some aural feedback.

Begin by creating an AudioSource as a Child of the Level01InformationZones GameObject

Add in the AudioClip you want to use for this

Set your Spatial Blend settings to 2D

Ensure that Play On Awake is Activated and that the AudioSource GameObject is Disabled

Finally, add in the AudioDisableAfterFinishPlaying Script to the AudioSource

Figure 13.4.4 Creating SubtitleVanishUIAudio AudioSource GameObject Disabled as Default, Activating PlayOnAwake AudioSource Parameter, and Adding AudioDisableAfterFinishPlaying Component

Next you will select one of the InfoZone GameObjects in this example I will choose InfoZone02.

Click on the small + symbol at the bottom right-hand corner of the On Exit () Event Component

Attach the AudioSource into this variable/drop target and set this to GameObject.SetActive

The GameObject.SetActive Function controls the checkbox immediately to the left of the GameObject name in the Inspector Panel (as indicated by the topmost arrow in Figure 13.4.5).

If there is a tick in this checkbox, the GameObject will be Enabled; if there is no tick, the GameObject will be Disabled.

Finally, Activate the checkbox to activate the GameObject when the subtitles appear, ensuring this AudioSource is using Play On Awake; this will result in the GameObject Enabling and the AudioSource playing the AudioClip when the On Enter () Event occurs as the player enters the Collider for the associated subtitle.

Figure 13.4.5 Adding Variable for On Exit () Event on InfoZone GameObjects Setting Function to GameObject.SetActivate and Assigning SubtitleVanishUIAudio GameObject

Playtest the game to check that the AudioSource is playing as intended when exiting the Sphere Collider Trigger Area Component connected to the InfoZone02 GameObject.

As with the appear/opening animation example, by using the AudioDisableAfterFinishPlaying Script to Disable the AudioSource after playing you are now able to repeat the earlier steps to Enable the same AudioSource for each of the subtitle appear animations, rather than creating individual AudioSources for each subtitle. One advantage of this method is that it will be easier and quicker to modify the volume/mix/AudioClip settings on a single AudioSource rather than having to modify several GameObjects.

There is an alternative method of setting this AudioSource to play; this could be used if you want to also use the RandomAudioPlayer script to randomly select from a number of AudioClips, including random Volume and Pitch settings. This is useful if you want more variation in the sound for this game mechanic. It is also a good example that, as with many things in Game Development, there is often more than one way to set up your Audio Implementation depending upon how you want the audio to function.

Create your AudioSource GameObject for the UI Subtitle appear SFX

Ensure this AudioSource GameObject is Enabled by default

Ensure Play On Awake is Disabled

Add in a RandomAudioPlayer Component

DO NOT add in or use an AudioDisableAfterFinishPlaying script

Add in your AudioClip and Min and Max Pitch and Volume settings

Select one of the InfoZone GameObjects as in previous method

Click on the + icon for the On Enter () Event

Assign the GameObject containing your AudioSource and RandomAudioPlayer Script

Set this Function to PlayRandomClip ()

Repeat the same steps to create an AudioSource and RandomAudioPlayerScript for the Subtitle Disappearing

Assign this Subtitle Disappearing GameObject to the On Exit () Event and set the Function to PlayRandomClip ()

Repeat the previous steps for all InfoZone GameObjects containing subtitles within both levels.

Figure 13.4.6 Alternative Setup Changing Function to Use RandomAudioPlayer PlayRandomClip ()

As with all other examples, you are able to accomplish this without adding any additional Scripts or modifying the code yourself for the 3D GameKit Unity Project. The Scripts and Components created for this project have provided a large number of flexible applications to create a variety of game mechanics and to allow you to implement and mix your own audio ideas to make these interactive, adaptive, and dynamic.

Unity Profiler

The Unity Profiler is a very useful development tool you can use to get performance information about your application while the game is currently being played.

The Profiler gathers and displays data on the performance of your application in areas such as the Central Processing Unit (CPU), Memory usage, Renderer, and Audio. It’s a useful tool to identify areas for performance improvement in your application and iterate on those areas. You can pinpoint things like how the code, Assets, Scene settings, camera, rendering, and build settings affect your application’s performance. It displays the results in a series of charts, so you can visualise where spikes in your application’s performance happen as you play through the game.

The Profiler does, however, have a specific Audio section that can be very useful in a number of different ways. You can use the Profiler to view what AudioSources are currently playing, what AudioClips they are playing, specific information about how they are playing such as 2D/3D positional information, are they looping, the volume, and how many times the sound has played in the level so far this playthrough.

This information can be very useful if, for example, you have accidentally set a sound to Loop, to play back 2D instead of 3D, or even if you have accidentally activated the Play On Awake parameter by mistake, causing the AudioSource to play as soon as the level begins. If you know the sound is playing from somewhere in the Scene, but are not sure exactly where in the level it is playing from, the Profiler can help you track what is currently happening in the game so you can then address and fix the problem.

You can view the Profiler Panel by using the top Menu and selecting Window > Analysis > Profiler.

Figure 13.5.1 Window Menu for Profiler Panel

If you begin to play the game, you can view all of the information for a number of systems, including CPU and Graphics Processing Unit (GPU) memory usage shown over time using the graphs. As stated at the beginning of this chapter, this book will not be exploring how to read each and every type of Profiler but instead will focus on the Audio-specific section.

You can close down/remove all sections of the Profiler that do not say Audio by left clicking on the dropdown icon in the top right-hand corner of the Profiler Modules. The added benefit of doing this is that your computer should run the Unity Project faster as it only needs to profile the audio system and not every individual system within Unity.

Figure 13.5.2 Closing Unnecessary Profiler Modules

First, you will click on the button labelled Simple and change this to Detailed.

You will also ensure that the Record button is Activated along the top Menu.

Figure 13.5.3 Profiler Audio Simple

When the game is running, you should see information about the audio within Unity displayed in real-time.

I find it most helpful to order the list by Audibility, as this is how loud the sound is currently when the Audio Listener position and real-time effects have been taken into account. This will let you see which sounds are loudest from the perspective of the player when they actually play the game.

Figure 13.5.4 Profiler Audio Detailed

Optimising audio files

Optimising how your audio files are stored in Unity can be used to decrease the final size of the finished game and is often a key part of finishing the game to ensure it runs as optimally at a consistent frame rate. This is slightly less of a concern for audio in PC games but is critically important for IOS and Android mobile phone applications and games. PCs, PS5s, and Xbox Series Xs have much larger hard drives than mobile phones. Within reason, a customer is less likely to be concerned with how much hard drive space a game requires for these consoles, but may decide not to download a mobile phone game if it requires a considerable amount of data and storage space.

One of the quickest things you can do to reduce the storage requirements for an audio file is to reduce the length of your loops or to use fewer variations.

Alternatively, you can also adjust the audio playback Sample Rate to reduce the file size for each Audio Asset.

Minute Stereo 16-bit, 48 kHz. wav file requires 11.3 mb of hard drive space

Minute Stereo 16-bit, 16 kHz .wav file requires 3.8 mb of hard drive space

As you can see, reducing the sample rate will dramatically reduce the file size, but this does come with a considerable downside. The Nyquist Theorem states that to reproduce a digital audio signal, the sampling frequency needs to be twice the highest frequency contained in the sound of the signal. This means that your sample rate needs to be double the highest frequency in the audio file.

A 48 kHz sample rate is capable of reproducing the full audible frequency spectrum from 20 Hz up to 24 kHz. A 16 kHz sample rate, however, can only reproduce frequencies up to 8 kHz. In this case, when reducing the sample rate, you are effectively applying a Low Pass Filter at 8 kHz and ensuring that any frequencies in the audio file above 8 kHz will be removed.

In real world terms this means that, if you have designed a SFX for say a magical spell and focused a lot of attention on the high frequency ‘sparkle’ of the sound between 8 kHz and 20 kHz, this element of your sound design will not be audible. When reducing the sample rate, you need to ensure that the sounds you are designing are not relying on elements of the frequency spectrum that downsampling will effectively remove.

When designing sounds for mobile applications, you may decide to set the maximum sample rate for all sounds at, for example, 16 kHz. This means that you will not be able to hear frequencies in your audio above 8 kHz and will need to account for this in your sound design. Setting a maximum sample rate for all sounds is much less common when designing sounds for PC, PS5, and Xbox One, as the file size requirements are often less restrictive.

Unity does have a very useful tool which can scan the audio file, work out what the highest frequency element in the audio file is, and then adjust the sample rate accordingly. The file size is then reduced, but you do not reduce the high frequency elements. This is very useful as you can use this to reduce the file size of sounds that only contain lower frequencies without artificially reducing frequencies, as the Low Pass filter Unity will use will be set to double the highest frequency of the sound.

Figure 13.5.5 Audio Asset Optimisation Settings in Inspector

After importing audio, you can click on Preserve Sample Rate (5) in the previous image and change this value to Optimise Sample Rate to make Unity automatically scan the audio file and adjust the sample rate accordingly.

You can also apply data compression to the Audio Assets to make the file sizes smaller. This is indicated by the Quality slider and can be adjusted between 1% and 100%. The more data compression you apply by reducing the quality of the audio file, the more audio artefacts that will be introduced.

To get a feel for how these settings will affect the audio playback, I would advise importing a complex audio file featuring the whole frequency range, such as a song you are familiar with. Then experiment with the various Sample Rate and Quality Settings to listen to how the various settings will introduce audio artefacts and reduce the high frequency content during playback.

Figure 13.6.1 Audio Asset Optimisation Settings in Inspector

Loading audio files

Setting your audio to the optimal load settings will greatly improve the performance of the game engine and is required for all professional releases to ensure the game will run well. The Load Type parameter (1) on the previous image shows how the audio has currently been loaded. This also works in conjunction with the Preload Audio Data (2) and Load In Background parameter.

It is a balancing act as the various loading methods all have advantages and disadvantages. Some are best suited to larger longer audio files such as music, and some for shorter sounds such as footsteps. This means that different types of Audio Assets such as music or footsteps perform best when set to load in different ways.

Figure 13.7.1 Resource Use of Compressed Audio by Load Type

There are three main ways in which audio can be loaded by Unity.

Decompress on Load

When using this option, Unity will store the file as compressed audio and then uncompress it before playing. This is why short pieces of audio, such as one-off environmental sounds that are required infrequently, benefit most from this option. Because of this, it is not advised to use this option for long files, such as environmental ambience loops or music, without introducing a significant performance overhead.

Compressed in Memory

Audio that is required frequently and immediately, i.e. footsteps or gunshots, cannot be streamed off a disk fast enough and should use compressed in memory, which utilises Random Access Memory (RAM). The advantage of using RAM is that you can load in a number of short sounds that can then be played back instantly using less processing power. The downside is that there is a limit to the amount of RAM available that must be shared between all development departments for things like art and animations alongside audio.

Streamed

Audio can be streamed from a disk or storage medium; an advantage of this is that you can load in longer files or files that may only play one time during game. It is typically used for larger files such as music, dialogue, and atmospheric background loops. A disadvantage is that you can only stream a certain amount of data, including audio files, at any one time.

Import settings cheat sheet

The following are generic suggested settings for medium sized games featuring up to 10,000 audio files.

As each game is different and has different requirements relating to optimisation, you need to take into account elements both across the entire game and at specific locations within it. You may find that certain scenarios require different load settings to perform optimally.

In the following tables: Y = Yes, N = No and N/A = Not Applicable/Option not available.

Table 13.1.1 Suggested Import Settings for PC/Console

Type of sound | Load in background | Load type | Preload audio data | Compression format | Quality | Sample rate setting
Dialogue | Y | Compressed in memory | Y | Vorbis | 70 | Preserve
Environment Loops | N/A | Streaming | N/A | Vorbis | 70 | Preserve
Environment Single Sounds | Y | Decompress on load | Y | Vorbis | 70 | Preserve
Foley | N | Compressed in memory | Y | ADPCM | N/A | Optimise
Footsteps | N | Compressed in memory | Y | ADPCM | N/A | Optimise
Main Music | N/A | Streaming | N/A | Vorbis | 85 | Preserve
Music Short | Y | Compressed in memory | Y | Vorbis | 85 | Preserve
Non-Dialogue Vocalisations | Y | Decompress on load | Y | Vorbis | 70 | Preserve
Gameplay SFX (Long) | N | Decompress on load | Y | Vorbis | 70 | Optimise
Gameplay SFX (Short) | N | Compressed in memory | Y | ADPCM | N/A | Optimise
UI SFX (Long) | Y | Decompress on load | Y | Vorbis | 70 | Preserve
UI SFX (Short) | N | Compressed in memory | Y | ADPCM | N/A | Preserve

Table 13.1.2 Suggested Import Settings for Mobile

Type of sound | Load in background | Load type | Preload audio data | Compression format | Quality | Sample rate setting
Dialogue | Y | Compressed in memory | Y | Vorbis | 50 | Preserve
Environment Loops | Y | Compressed in memory | Y | Vorbis | 40 | Preserve
Environment Single Sounds | Y | Decompress on load | Y | Vorbis | 50 | Preserve
Foley | N | Compressed in memory | Y | ADPCM | N/A | Optimise
Footsteps | N | Compressed in memory | Y | ADPCM | N/A | Optimise
Main Music | N/A | Streaming | N/A | Vorbis | 70 | Preserve
Music Short | Y | Compressed in memory | Y | Vorbis | 70 | Preserve
Non-Dialogue Vocalisations | Y | Decompress on load | Y | Vorbis | 50 | Preserve
Gameplay SFX (Long) | N | Decompress on load | Y | Vorbis | 50 | Optimise
Gameplay SFX (Short) | N | Compressed in memory | Y | ADPCM | N/A | Optimise
UI SFX (Long) | Y | Decompress on load | Y | Vorbis | 50 | Preserve
UI SFX (Short) | N | Compressed in memory | Y | ADPCM | N/A | Preserve

Warning

If you pitch up or down any Audio Assets in Unity, then you should set the Sample Rate to ‘Preserve’, to ensure you will not encounter issues due to the Nyquist Theorem when Unity is re-sampling.

You can left click to select the first Audio Asset, hold down the shift key on the keyboard, and then left click on the final Audio Asset to select multiple files in a single Unity folder. Alternatively, select one of the Audio Assets and then press Ctrl + A on PC or Cmd + A on Mac to select all Assets in that folder. You can apply a similar change to multiple files at once, saving you valuable time.

5 quick tips

When the Profiler Panel tab has been added to Unity, you may notice that your computer will perform more slowly. This is because the Profiler is performing a number of complex analytical functions. I would advise closing the Profiler Panel when you do not require it to minimise the processor overhead.

You can also click on the name of the GameObject or Asset column in the Profiler to have the relevant AudioSource highlighted in the Hierarchy. This is very useful for finding sounds that are playing unexpectedly, if you have accidentally added an AudioSource set to Play On Awake within a GameObject deep within the Hierarchy structure by mistake.

The DamageableEnableGameObject Script could also potentially be used on the Grenadier boss enemies, as they have three health points each, by adding this into the GameObject containing the Damageable Script. It will not work on the Chompers or the Spitter enemies, however, as these only have one health point each.

The Additional Audio Scripts have been coded in such a way that they can be used together to create quite complex behaviour. The GameObjects attached to the Scripts do not all have to be Enabled when starting the level. For example, a CountDownEnable Script could be activated by a Trigger Area. When the timer has counted down, this could Enable an AudioSource GameObject. The AudioSource GameObject could then also be using a Fade In Volume Script.

If you are trying to implement or troubleshoot your own creative audio mechanics or ideas, if something is not working, remember to check the Console Panel for any errors. It can also help to write out the logical flow of the events and GameObjects, much like the short explanation at the end of the Interactive and Adaptive Music section. Use this to go through from the start of the logical chain of GameObjects and Components to test and see if each part of the mechanic is working as you intended. Make use of the Profiler and Console Panels and refer back to particular sections of this book if necessary.

Tip

Now armed with the Fade In and Fade Out Volume Scripts, consider revisiting your Trigger Areas in the game to adapt your implementation. Think how you could use these tools to create a smooth-sounding crossfade between two AudioSources rather than having your GameObjects simply just Enable and Disable.

Try first and experiment to see if you can work this out yourself. If you do struggle, check out the GameObjects named Trigger Enter 3rd Room Corridor and Trigger Enter 4th Room Rising Platforms in Level02 if you want to see how this could be set up.

Chapter 13 practical tasks

The practical task for this chapter is to implement audio into the mechanics covered in this chapter.

This will enable you to include a higher level of detail within the audio and should contribute to your finished project being comparable with current professional games.

Adding SFX to Ellen’s Shield Mechanic

Adding SFX for Ellen’s Respawn Mechanic

Adding Additional Ambient SFX to the Staff Weapon on the Podium in Level01

Adding Start and Stop SFX for the Rising Platforms

Adding Additional SFX to Chomper Death Particles

Adding in a One Shot Sound at the Beginning of Spaceship Arrival Animation at end of Level02

Adding SFX when Ellen Loses a Health Point or Regains Health

Adding SFX when Ellen’s Remaining Health Points are Low

Adding SFX to the Dialogue UI Animations

Optional additional task

As an additional task, take a screenshot of the audio memory values in the Profiler when the game is running, then perform the optimisations as outlined in this chapter. Then take a second screenshot of the Profiler when the game is running to compare and see how much valuable memory you have saved.

14 What to do next

DOI: 10.4324/9781003055167-14

Well done if you’ve made it this far!

By completing all the practical tasks in this book, you’ve learned a large number of skills relating to interactive, adaptive, and dynamic audio within the Unity game engine. You should now also have a fully playable game featuring all of your own audio. At this point you might be thinking about where to go from here? What areas to focus on? Or how to use the knowledge you have gained to break into the industry and land a Game Audio job?

This chapter will put the theory and knowledge of practical application you have gained into context as well as offer additional tips on how to produce a Game Audio demo reel for future job roles and how best to present this to potential employers. It will also provide recommendations for additional learning materials depending upon what Game Audio skills you want to develop further in the next stage of your career.

There are a number of different paths you can follow, particular skills you may wish to develop or goals you may want to achieve. The following are three main areas of focus. You can choose to devote all your time and attention to one of these areas or split your attention to gain skills in all three simultaneously.

Job applications

The games industry has been growing exponentially year after year; the video games industry annual revenue has now eclipsed that of the music and film/TV industries put together. It was estimated to be worth $162.32 billion in 2020 and is expected to reach a value of $295.63 billion annually by 2026. To put this into context, according to the website www.steamspy.com, there are now more than 35,000 games on Steam alone (excluding DLC); 8,256 of these were new releases in 2019. The vast majority of these will feature some form of interactive audio and will require someone with the skillset to record/create, implement, and then mix this audio.

If you want to turn your Game Audio passion into a full-time career, the first step to this process is obvious; you need to apply for a job. But what do game studios expect from an applicant, how best should you impress them, and what is a typical interview process like?

Large AAA game developers with 300–1000+ employees often have a number of audio people working on a project, usually with a clear and defined hierarchy of job titles and responsibilities. In smaller independent game studios with fewer than 100 employees in total, it is not uncommon for one or two people to perform all of the roles listed in the following.

Figure 14.1.1 Job Titles and Typical Audio Department Structure in AAA Games Development Company

In large AAA games studios, the Audio Manager role is typically held by a single person, and as the job title states, the Audio Manager is the person responsible for managing the overall audio for a game project. This person usually focuses the majority of their time on planning budgets and dealing with big picture issues such as determining how many members of staff are needed for a project and overall timescales, rather than actually working directly on the game.

The Audio Lead is responsible for the day-to-day planning for the project, assigning individual tasks to members of the audio team and ensuring the larger timescale tasks are completed on time and to a high standard. Depending upon the size of the games company, this position can be held by one or two people sharing the responsibilities. To apply for this job in a AAA studio, you typically require around ten years of experience and will have to be a seasoned veteran within Game Development with credits on a number of notable games.

The Audio Programmer will be responsible for writing larger overall code systems within the game, such as creating a reverb system or improving how the audio files are stored and loaded. To put this in a Unity context, this is the person or department responsible for creating the AudioSource or Reverb Zone Components. They would not actually spend their time adding these Components to GameObjects or mixing the audio within a particular game, which are the things we have covered within this book. Typically, an Audio Programmer’s background will feature more coding knowledge and education rather than a focus on sound design.

In certain respects, The Technical Sound Designer acts as the bridge between the Audio Programmer and the Sound Designer by creating the audio files. They are responsible for using the coding framework developed by the Audio Programmer. In the context of the 3D GameKit Project, this would be the person going through the various code scripts for each game mechanic and adding in the public variables/drop targets for the Sound Designers to place their AudioSources into. So again, this position would focus more on coding skills rather than sound design creation or mixing.

A Senior Sound Designer is generally responsible for helping or mentoring the more inexperienced or junior members of the audio team. To gain this title, you will typically need about five years of experience working on a number of different games, and could almost be considered the line manager for the Sound Designers depending upon the scale of the project or size of the studio. They’re usually responsible for actively working on the audio for the game and providing advice or answering any questions from Sound Designers or Junior Sound Designers.

The title Sound Designer within large AAA companies is normally awarded after gaining two or three years of experience. In terms of AAA games, you may have only completed a single game project start to finish, known as a full cycle.

Junior Sound Designer is the starting position within audio game development; this position is most likely to be best suited to you. Typically, Junior Sound Designers have knowledge to create, implement, and mix sounds and dialogue but may not have much, or any, experience actually working on a professionally developed game.

This information on specific job titles is a rough overview of each person’s role. In different companies, the exact responsibilities may be shared slightly differently. They may have specific job roles with reduced or additional responsibilities to the ones I have outlined. As a general rule, the bigger the games company and the more employees it has, the more specialised each role is. In very large companies such as Rockstar, EA, or Ubisoft, it is not uncommon to have an audio person whose full-time responsibilities are to record, edit, and process all the dialogue. Likewise, they may also hire Sound Designers who will exclusively design and make the sounds using a DAW and not actually work within the game engine itself at all. In these cases, the implementation and mixing tasks are handled by a separate audio department.

Junior Sound Designer applications

The following information is tailored specifically to applying for your first Junior Sound Designer position.

If you are considering applying for a Junior Sound Designer role, I would advise you to begin by either using a job search website and searching for ‘Game Audio’ or ‘Sound Designer’ or looking on the jobs/careers section of any local games studios. Begin by having a look at the qualifications or experience/skills required and, if needed, widen your search worldwide to gain an overview of the most common requirements.

Next is a list of the requirements I have seen most frequently in the majority of Junior Audio job listings:

Very strong, demonstrable sound design and editing skills (demonstrated in show reel)

Ability to design audio for a range of styles (from abstract to ultra-realism)

Experience designing and implementing audio for games or film (like working on the practical projects in this book)

Mastery of at least one DAW (REAPER and Pro Tools are most common mentioned)

Knowledge/experience with either Unity or Unreal game engines

Proficient in Wwise, FMOD audio middleware (additional pieces of audio software discussed later in chapter)

Knowledge of the production processes of Game Development (the information in Chapter 6 is directly relevant to this)

Solid knowledge of PC environments (typically, games are developed on Windows PCs)

Relevant audio education credentials (typically, a degree in Audio/Music Production)

You don’t need to wait until you find an open job listing to begin preparing, but what does this actually involve?

It may sound like a given, but have your CV completed and ready to send at a moment’s notice.

Make sure it looks professional and only has relevant audio experience, qualifications, and achievements. No one needs to know about the egg and spoon race you won at age 6 or the summer job you had working in a restaurant. Finally, ensure you check that any links you include are working and the contact information you include is accurate. I would also advise you to limit your CV ideally to one page but no longer then two. If you do not have multiple years of experience in Game Development, don’t worry; you don’t need to pad out your CV to fill five pages if most of the information is irrelevant. A games recruiter would prefer to read a single page or two about directly related and relevant information and experience.

You will need to create a video demo reel showing your sound design experience, and this is arguably more important than the ‘previous experience’ or ‘credits’ on your CV. It will demonstrate to any potential employer that your sound design and mixing abilities are at professional standard and that you understand how to create sounds that work alongside moving images.

I would advise you to create a one-minute showreel. This may sound very short, but believe me, if you are looking through 100+ applications, you can often tell within 20–30 seconds the approximate level of someone’s sound design skill. Record or download three 20-second video clips featuring gameplay from different games that will demonstrate a variety of sound design techniques and styles. Import the videos into your DAW of choice and remove the original audio. Then recreate and mix your own audio on top of these video clips. For this one-minute showreel, it is not advised to include any music in the clip. The person listening to your audio wants to hear all the detail within your sound design and mixing abilities and music can be used to obscure this or attempt to hide sloppy unprofessional sound design.

When uploading the finished video to the internet, make sure you include a short title card at the beginning and end of the video featuring your contact info and stating that the audio within is a ‘Sound Re-Design’.

When you have your one-minute reel, you could add links at the end to longer, more detailed showreels.

If a recruiter is impressed with your minute-long reel, they may then be willing to watch a longer video demonstrating other projects in more detail. Your other videos could include longer additional showreels. What would be likely to further impress them is if you captured gameplay from your finished 3D GameKit Project. You could do a short playthrough with visual annotations along the bottom of the screen detailing your role in the project, i.e. designing all the sounds, recording and implementing the dialogue, and composing/editing the music alongside balancing/mixing the entire game. Consider recording a short commentary as you play through the game, explaining your choices in terms of sound design, mixing, and implementation used throughout the project. Having an additional showreel video demonstrating sound design implementation and mixing within a game engine will provide context and demonstrate working knowledge, experience, and best practices. This should go a long way to helping set you apart from other potential applicants who only have linear sound design experience.

For additional tips on creating or improving your Game Audio showreel, I recommend that you search YouTube for ‘Game Audio Demo Reel’ to look at other people’s work for reference or ideas. I would also recommend the following Twitch channel www.twitch.tv/powerupaudio as this is dedicated to reviewing Game Audio demo reels.

So, at this point you have a well-formatted and concise CV; you have a one-minute demo reel featuring great sound design and a number of additional showreels featuring audio and video captured from inside your final Unity game project. You’ve just spotted your dream Junior Sound Designer job at your favourite games developer and sent off the application.

At this point you’re probably wondering, ‘What is the typical recruitment process like?’

After the initial application, you will receive an email letting you know if your application has been unsuccessful or if you have been shortlisted. If successful at this point, you will often be invited for an interview with a HR representative and someone from the audio team.

Before this interview, ensure you thoroughly research the company; look for the credits list on a recent game they created or on LinkedIn for the people who worked on it and search their names. Have they written any articles or given any talks? Or is there any additional information you can discover that may help prove your willingness to go the extra mile or provide you with some talking points during the interview?

This first interview is normally more of an informal chat about you and your experience and is a good chance to ask any questions you have prepared. It is normally used by studios to determine if you have been truthful in your CV, to give you a chance to expand and explain about any areas of experience you have mentioned, and to see if you could be a good fit culture-wise with the studio.

If this stage goes well, you will often be given a short sound design task to complete; normally you will have a week to complete this. The tasks may differ between various studios, but for the majority of these you will be given a short video clip and asked to design sounds to accompany the visuals using your DAW. You will need to very carefully read any additional instructions such as how the audio/video file is to be submitted or if they would also like a short essay detailing your thought process for the task. Failure to follow these instructions exactly, will all but rule you out for the job.

After submitting the audio task/test, if the studio is impressed with what you have created, you may be invited for a second and usually the final interview. It is during this that you may be asked about specific techniques or creative choices you made when completing the test. This interview may also include your salary expectations and will provide you with a chance to ask any final questions you may have. If this second interview is a success, you will likely be offered the job.

If you should ever find that you are unsuccessful at any stage of the application process, it is a really good idea to send a short email to the company thanking them for their time. This is also an opportunity to ask for some feedback on your application so you know what to focus on the next time you apply for a job. Most studios will send you a few short bullet points; take these points on board, review the feedback with an open mind, and attempt to revisit the practical test or your CV to implement the feedback. This should hopefully improve your chances on the next interview.

As game studios may receive a large number of responses for any available jobs, it is advised to submit your application as early as possible. This helps ensure that your application should be one of the first they will look at, and just in case the studio decides to close the application process early due to receiving a large number of applications.

When reviewing the job listings for Junior Sound Designer or Sound Designer, you may see that many jobs ask for two ‘shipped’ (completed) games or equivalent experience. This is a problem that applicants in many different industries face when trying to get on the first rung of the career ladder and often leads people at the beginning of their career to ask, ‘How do I get the experience required to get a job, if I can’t get my first job without first having the experience?’

Gaining additional experience

Experience can be gained in many different ways. I will outline a few different options.

Additional Unity levels

Unity has a number of additional game levels that can be downloaded for free on the Unity Asset Store, such as the Unity 2D GameKit, Unity FPS Sample, and the Unity Karting Microgame, alongside a vast number of individual levels you can download from third-party creators. By downloading, creating, and implementing your own audio within these levels, you will begin to prove that you have the experience required to work on a professional game. In addition to this, it also demonstrates that you are capable of finishing multiple projects to a high standard.

Game Jams

Game Jams are where both hobbyist and professional developers meet up to attempt to create a game in a very short amount of time, typically over a weekend. Search your local area/nearest city and ‘Game Jam’ on the internet to see if there are any upcoming events held nearby. If there are no events held locally, then consider joining an online Game Jam. This can also be a great way to network and meet people. Not only will this potentially give you an additional game credit, but some game studios may be more willing to overlook the experience requirement if you have a personal recommendation from someone you’ve done a game jam with who is currently working in the industry.

Online indie developers

Join some Game Development forums and search for the ‘classifieds’ section.

Quite often, you will find a number of developers working on a game as a hobby to try to gain experience like yourself. You will not usually be paid upfront for any audio work, but may be able to negotiate a revenue share of any potential profits.

Volunteer

There’s nothing wrong with contacting your local game studios and offering to volunteer some of your time on a short-term basis to help them with some small tasks. Again, this can be a great method of networking and may let you gain some valuable experience; it was the method I used to make my first contacts within the industry. I volunteered to do some of the more menial dialogue editing and file renaming tasks for two weeks. At the end of this time, I was offered a six-month paid contract to finish off the remainder of the project, gaining my first credit in a professionally developed game and the contacts that kick-started my career.

There is an excellent free resource compiled by Florian Ardelean called The Bible of Getting a Job in Game Audio, 2020 Edition, consisting of a Google Doc/PDF. This resource currently available at the following website address: www.florianardelean.com/blog contains interviews and advice from dozens of Game Audio professionals, which will outline and expand upon in great detail the brief points outlined in this chapter.

Middleware

Middleware may or may not be a term you have heard before in relation to software. In Game Audio terms, it is the name given to an additional piece of audio software that can be used in conjunction with a game engine. It is often used to allow Sound Designers to have greater creative control over the audio than using AudioSources within Unity. In essence, it’s a program created specifically for controlling audio within a game engine and will contain all the features provided by the ‘Additional Audio Scripts’ as discussed within Chapter 13 of this book. Many of these features will effectively work ‘straight out of the box’ without requiring additional code scripts along with access to a number of more advanced features. The two most common examples of Middleware are FMOD, created by Firelight Technologies, and Wwise by Audiokinetic. There are a few other independent options, such as FABRIC by Tazman-Audio, that are less expensive, but they generally do not have as many features or as much documentation.

So, if Audio Middleware is so great, why don’t all games use it, or why is it only mentioned at this point in the book?

The reason that not all games will use Audio Middleware is that it can be relatively expensive to license for your game, and smaller independent studios may not have the budget for it. An additional reason is that not all games will really benefit from the additional features offered by using Middleware. For example, to license the ‘premium’ version of FMOD with access to the source code needed to modify its behaviour will cost $15,000 per game project. Wwise costs $18,000 for a similar license with additional fees per platform/console at time of writing. This cost can push it beyond the budget for many smaller independent games and studios.

One of the main purposes of this book was to enable you to make your own audio and have this play interactively within a playable game project without delving into coding or additional pieces of software. The reason Middleware has not been covered in this book is that much like DAWs, there are a large number of skills and knowledge that can be transferred between Unity and FMOD/Wwise, if you now choose to learn how to use these pieces of software.

If you want to work specifically on large budget AAA games, I would recommend becoming familiar with both Wwise and FMOD. As with most subjects, there is a large amount of information available on the internet; there are also a number of books that are recommended. Many of these resources will assume you have a good level of knowledge regarding Unity or may not explain individual features in as much detail as in this book. Having already gained this baseline knowledge should enable you to progress in your studies without becoming immediately overwhelmed.

Game Audio with FMOD and Unity by Ciarán Robinson

www.audiokinetic.com/learn/certifications/

Programming

Learning programming, or as it’s often simply called, coding, can be a very daunting task for a number of reasons; it is a completely different skill set than typical audio engineering. It requires a large amount of knowledge about a great many different Unity systems to implement your ideas, and in addition to all of this, it is very precise. For example, a single small typo can stop the entire game from being able to be played in the Unity engine.

So, why would you want to learn to code? First, it can make you a self-sufficient Game Developer/Sound Designer. This means you do not have to rely on any other members of the development team to go into the Scripts for each game mechanic and add in the AudioSource public variables for you.

Second, if you are working freelance or charging on a per project basis, doing more work means you can charge more money for your added expertise and the additional time required for adding in the audio code. Having additional skills makes you more desirable when applying for jobs, especially in smaller companies with fewer employees.

Finally, it will give you a much better overview of how the code within the game is working and how this may potentially affect the audio.

An internet search of ‘How to begin learning programming’ will inevitably bring up a myriad of information, with people arguing about the benefits of specific coding languages (much like audio people argue about which DAW, mic, or plugin is best), and a large amount of seemingly unrelated information that can make the topic seem very intimidating for a newcomer (also quite like audio equipment forums).

Different game engines (and software development in general) use different coding languages, and this book will not get into the specifics of each or the benefits of one over another. Unity uses a programming language called C# and the Unreal engine uses C++. The Unreal engine, however, has the ability to use a form of logic events called BLUEPRINTS. BLUEPRINTS work similarly to the audio software Reaktor or Max MSP, where you can create different behaviour by drawing lines between nodes, also known as Visual Scripting.

Figure 14.3.1 Unity Code on Left, Unreal BLUEPRINTS on Right

At this point, the choice is yours; it could be argued that creating more complex behaviour for audio may be simpler or more intuitive using the BLUEPRINT visual coding system to connect various modules together, but this would require you to learn the fundamentals of the Unreal game engine.

If you wish to learn to code using Scripts as used within Unity, having already learned about a great number of Components and functions within the game engine should reduce the initial learning curve.

In my experience learning to code within Unity, actually adding in the public variables and setting them to play, stop, or change an AudioSource parameter can be accomplished fairly simply with only a few lines of code required. Making this happen alongside a corresponding event, however, requires a thorough understanding of many different coding aspects within Unity. You need to be able to read and understand the existing code to then know where to place your few lines of audio code to make the sound play or trigger at the correct event in the game.

Speaking for myself, I am much better at reading and understanding the existing code within the game mechanics than I am at actually writing lots of complex code. This is due in part to the previous statement; the majority of audio code can simply be getting a sound to play at the right time. To accomplish this, I spend most of my time reading the existing code to work out where to add in my fairly simplistic audio code, for example, to play a sound when a character dies, respawns, or attacks (like the RandomAudioPlayer AudioSource GameObject Variables as demonstrated in the 3D GameKit Project).

If you are serious about a career in Game Development, I would say that it is equally important to be familiar with both the Unity system of coding using Scripts and the Unreal BLUEPRINT system. Most game studios will use either one of these or their own in-house engine will use a similar/comparable system.

The skills you will learn using one game engine are transferable to another. Having learned several game engines myself, including Unity, Unreal, and numerous in-house game engines, I can equate this process to learning a new DAW. As you probably remember, the first DAW you learn is by far the most difficult and time consuming because every process, Menu, tool, and technique is brand new. Learning a second DAW should be simpler, quicker, and easier because you have already learned about and mastered a number of skills to do with audio recording, editing and mixing. Learning a third or a fourth DAW should be even faster, easier, and quicker again as you are basically just learning keyboard shortcuts and the unique names and Menus used for what are essentially very similar processes and functions.

I will outline a few resources you can use to learn either of these methods of programming.

Unity

Principles of Game Audio and Sound Design by Jean-Luc Sinclair

C# Game Programming Cookbook for Unity 3D by Jeff W. Murray

Learning C# Programming with Unity 3D by Alex Okita

https://unity.com/learn

Unreal

Game Audio Implementation by Richard Stevens, Dave Raybould

Game Development and Simulation with Unreal by Alireza Tavakkoli

https://www.unrealengine.com/en-US/onlinelearning-courses

Chapter 14 practical tasks

The practical task for this chapter is, first, to congratulate yourself on a job well done for completing the tasks and gaining the knowledge within this book.

To successfully obtain a Game Audio job, ensure you have the following prepared and ready for the next time you get an opportunity or see a job advertisement:

Create a one-minute Sound Design Showreel

Create additional supplementary, longer showreels using video captured from your 3D GameKit

Update your CV

Research any nearby game studios and sign up for job alerts or local game dev networking events

Decide what additional skills you want to develop further and put a plan in place for achieving these

You are now ready to take the knowledge you have gained to take your next step in your Game Audio career!

Cheers

As anyone who knows me either personally or professionally, I’m not one for long, drawn-out speeches. Since this is a book and not an Oscars acceptance speech, the following is a list of people (and a few pets) to whom I owe a great deal of gratitude to for their help, support, and guidance.

Aaron Brown

Da

Jean Paul Adams

Jen

John Attewell

Jon Thornton

Marios Aristopoulos

Mum

Orna Herr

Paddy Craig

Paul Johnson

Paul ‘Stak’ Stakounis

Rez

Robyn Piercy

Saltopus

Simon Leary-Wood

Tom Wolland

Torr

Cheers

Glossary

3D GameKit Also known as the final game project, this is the Unity 3D GameKit Project featured within Chapters 6–13 of this book.

Asset An asset is any file that is imported into Unity.

AudioClip An audio asset within Unity.

Audio Implementation The process of getting audio to function inside of a game level.

Audio Mixer Group A sub-section of the Unity Mixer, these are effectively busses you can route AudioSources Outputs to.

AudioSource The main Audio Component in Unity that allows you to control how an AudioClip will play back/sound in the game.

Collider A component most commonly shaped as a sphere or a box, placed in the level and used to detect collision.

Collision When two or more GameObject collide or touch one another.

Console Panel A Panel within Unity that will show you any errors that have occurred.

DAW A Digital Audio Workstation is a piece of software used to record, edit, and process audio files.

Diegetic A sound source that comes from somewhere on screen and would be heard by the characters.

DLC/Downloadable Content This refers to the additional resources and projects that accompany this book.

Edit Mode One of the main modes in Unity, this is used when adding in GameObjects, Components, or changing Parameters. Any changes made in this mode can be saved.

End user The average person/consumer who will play the game when it is released.

Final Game Project The Unity Project featuring a playable game featured within Chapters 6–13 of this book.

Frequency Masking This acoustic phenomenon occurs when the perception of a sound is affected and covered by another currently playing sound, often in the same frequency range.

GameObject When something has been added within the level, it is known as a GameObject or object inside the game.

Gizmo A visual render enabling you to see at a glance where particular components are positioned in the Scene view.

Hierarchy A Panel that contains the name and structure of every GameObject in the current Scene.

Implementing Refers to the process of adding in specific behaviour to the game, in the case of audio often getting an audio file to play back at the correct time using the correct parameters.

Inspector A Panel that displays contextual information about assets and also the list of Components when a GameObject is selected.

Layers A method of grouping together GameObjects into specific categories which can then enable components to function in a specific way such as the Collider Layer activating the Collision function.

Middleware An additional piece of software that can be used in conjunction with Unity and will often be used in place of existing systems, such as Unity’s audio components.

Non-Diegetic A sound source that comes from somewhere on screen and would be heard by the person playing the game, but not by the characters within the gameworld, such as background music.

One Shot A singular sound designed to play from start to finish.

Operating System The low-level software that supports a computer’s basic functions, such as Microsoft Windows or Apple OSX.

Panel A specific window within Unity.

Placeholder A temporary file that is quickly added to test functionality and will be replaced/updated at a later date.

Playable Character This refers to the character the Player is currently controlling or playing as.

Player This refers to the person who is playing or in the future will play the game.

Play Mode One of the main modes in Unity and is used to play through the game or level to see and hear your changes to the game.

Play On Awake A function of the AudioSource Component used to make the AudioSource instantly play when Enabled.

Prefab A type of asset in Unity, often used to group together collections of GameObjects to create templates allowing you to make changes to multiple GameObjects without requiring these actions to be performed individually on all instances.

Project Panel A Panel within Unity that will contain all of your Game Assets.

Proximity Effect A natural acoustic phenomena in which lower frequencies are increased the closer you are to a sound-emitting source.

Public Variable Parameters on a script that a programmer can make available to be edited without requiring modifications to the actual code file. (In this book often simply called Variables.)

RandomAudioPlayer A specific script created to allow you additional control over the AudioSource Component.

Real Time A computer program or game must be able to respond instantly to input from the player. In Unity, this means you are able to change parameters of the game engine and hear these effects immediately without having to stop and then restart the current game level.

Scene A file that contains a game level within Unity.

Scene View A Panel within Unity showing all of the GameObjects currently active in the level, also known as the Level Editor View.

Script A piece of code within Unity written to perform a specific function or set of functions.

Seamless Loop A looping audio file that has no discernible start or end point.

Trigger Area A collection of components that can detect when a GameObject is entering, within, or exiting another Game Component. This can then produce specific behaviour such as starting or stopping playback of sounds.

Unity Mixer Group AudioSource Outputs can be routed to a specific group on the Unity Mixer that functions like an Auxiliary track in a DAW.

Unity Mixer Panel A Panel within Unity that will allow you to control the Unity Audio mixer.

Variable Variables are containers that hold information. They allow you to label and store data in memory and change specific references within the code.

Zero Crossing Point The point within an audio file where the sample/cycle is at unity gain, neither positive nor negative.

Index

3D GameKit Project 150, 169

Asset 12, 72–9

AudioClip 83–6

Audio Implementation 98, 132, 150

Audio Mixer Group 307–9, 311–3

AudioSource 80, 82–3

Chomper 236–8, 327, 353

Collider 103, 171

Console Panel 158–9, 387

Diegetic 37, 51, 57

Edit Mode 71, 92–3

Ellen 229

Frequency Masking 42–4

GameObject 13

Gizmo 19, 26, 88, 173

Grenadier 242

Inspector Panel 26

Layers (Sound Design) 42–3, 47, 53

Layers (Unity) 175

Middleware 396

Move Tool 13–15

Non-Diegetic 37, 42, 56

One Shot 41, 68, 217

Operating System 4, 10

Playable Character 229

Play Mode 71, 92–4

Play On Awake 83, 96, 112

Prefab 115–9

Project Panel 11–12

Proximity Effect 47

RandomAudioPlayer 217

Rotate Tool 13, 15

Scale Tool 13, 15–16

Scene (File) 12,

Scene (Panel) 13

Script 105–8

Seamless Loop 57

Spitter 238–42, 353, 356–8

Trigger Area 103, 170–1

Unity HUB 5–10

Unity Mixer Panel 305–7

Variable 104–5

Zero Crossing Point 59, 61–2