Sonity 1.0.5 Documentation

Audio Middleware for Unity

Table of Contents

Table of Contents

1 Getting Started

1.1 What is Sonity?

1.2 Video Tutorials

Sonity - Showcase

Sonity - Quickstart Tutorial

Sonity - Realistic Gun Sounds Tutorial

Sonity - SoundPhysics & Intensity Tutorial

1.3 Installation

1.4 Adding the SoundManager

1.5 Asset Creation

1.6 Asset Editing

1.7 Shortcuts

1.8 Playing and Stopping Sounds with SoundTrigger Basics

1.9 Playing and Stopping Sounds with C# Basics

1.10 Templates & Examples

Example_AudioMixerWithLimiter.mixer

TemplateSoundMusicManager.cs

TemplateSoundPlayUI.cs

TemplateSoundVolumeManager.cs

1.11 Unity Native Audio Support

1.12 How To

How To - Optimize AudioClip Settings

How To - Debug Sounds and Performance

How To - Rename A Lot of Assets

How To - Force Resave Assets

1.13 Sonity Changelog

2 Create Assets From Selection

3 SoundContainer

3.1 SoundContainer Presets

3.2 SoundContainer Preview

3.3 SoundContainer AudioClips

3.4 SoundContainer Settings

3.5 SoundContainer Volume

3.6 SoundContainer Pitch

3.7 SoundContainer Spatial Blend

3.8 SoundContainer Spatial Spread

3.9 SoundContainer Stereo Pan

3.10 SoundContainer Reverb Zone Mix

3.11 SoundContainer Distortion

3.12 SoundContainer Lowpass

3.13 SoundContainer Highpass

3.14 SoundContainer Find References

4 SoundEvent

4.1 SoundEvent Presets

4.2 SoundEvent Mute, Solo, Disable

4.3 SoundEvent Preview

4.4 SoundEvent SoundContainers

4.5 SoundEvent Timeline

4.6 SoundEvent Modifiers

4.7 SoundEvent Settings

4.8 SoundEvent Intensity

4.10 SoundEvent Trigger On Play

4.11 SoundEvent Trigger On Stop

4.12 SoundEvent Trigger On Tail

4.13 SoundEvent SoundTag

4.14 SoundEvent Find References

5 SoundEvent Functions

5.1 SoundEvent Play

5.2 SoundEvent PlayAtPosition

5.3 SoundEvent Stop

5.4 SoundEvent Pause and Unpause

5.5 SoundEvent Get State, Length and Time

5.6 SoundEvent Get Spectrum Data

5.7 SoundEvent Load or Unload Audio Data

5.8 SoundEvent 2D Play

5.9 SoundEvent 2D Stop

5.10 SoundEvent 2D Pause and Unpause

5.11 SoundEvent 2D Get State, Length and Time

5.12 SoundEvent Music Play

5.13 SoundEvent Music Stop

5.14 SoundEvent Music Pause and Unpause

5.15 SoundEvent Music Get State, Length and Time

6 Modifiers

7 SoundParameter

8 SoundParameterIntensity

9 SoundTrigger Component

9.1 SoundTrigger Custom Override

10 SoundTrigger Functions

10.1 SoundTrigger Play

10.2 SoundTrigger PlayAtPosition

10.3 SoundTrigger Stop

10.4 SoundTrigger Pause and Unpause

10.5 SoundTrigger Get State

10.6 SoundTrigger Load or Unload Audio Data

11 SoundPhysics

11.1 SoundPhysicsCondition

12 SoundPicker

13 SoundPicker Functions

13.1 SoundPicker Play

13.2 SoundPicker PlayAtPosition

13.3 SoundPicker Stop

13.4 SoundPicker Pause and Unpause

13.5 SoundPicker Get State, Length and Time

13.6 SoundPicker Load or Unload Audio Data

14 SoundMix

15 SoundPolyGroup

16 SoundTag

17 SoundPreset

18 SoundDataGroup

19 SoundManager Component

19.1 SoundManager Settings

19.2 SoundManager Performance

19.3 SoundManager Debug SoundEvents Live

19.4 SoundManager Global Statistics

19.5 SoundManager Instance Statistics

19.6 AudioListenerDistance Component

20 SoundManager Functions

20.1 SoundManager.Instance Play

20.2 SoundManager.Instance PlayAtPosition

20.3 SoundManager.Instance Stop

20.4 SoundManager.Instance Pause and Unpause

20.5 SoundManager.Instance Get State, Length and Time

20.6 SoundManager.Instance Get Spectrum Data

20.7 SoundManager.Instance Load or Unload Audio Data

20.8 SoundManager.Instance 2D Play

20.9 SoundManager.Instance 2D Stop

20.10 SoundManager.Instance 2D Pause and Unpause

20.11 SoundManager.Instance 2D Get State, Length and Time

20.12 SoundManager.Instance Music Play

20.13 SoundManager.Instance Music Stop

20.14 SoundManager.Instance Music Pause and Unpause

20.15 SoundManager.Instance Music Get State, Length and Time

20.16 SoundManager.Instance Global Pause and Unpause

20.17 SoundManager.Instance Global Volume

20.18 SoundManager.Instance Global SoundTag

20.19 SoundManager.Instance Global Distance Scale

20.20 SoundManager.Instance Speed Of Sound

20.21 SoundManager.Instance Voice Limit

20.22 SoundManager.Instance Disable Playing Sounds

1 Getting Started

1.1 What is Sonity?

Sonity is an audio middleware giving you full control of your sound, all within Unity.

Balancing ease of use with advanced features it will help you to quickly make your game sound good.

Helpful Links and Info

1.2 Video Tutorials

Sonity - Showcase

Link to video

0:00 Intro

0:19 Features

1:31 Outro

Sonity - Quickstart Tutorial

Link to video

0:00 Intro

0:19 Installation

0:49 Asset Creation

1:41 Asset Editing

2:53 SoundTrigger Implementation

3:15 C# Implementation

4:34 Outro

Sonity - Realistic Gun Sounds Tutorial

Link to video

0:00 Intro 

0:45 Distance Crossfades

3:22 Pistol Shot Editing

4:30 Adding SoundTags

5:44 Play Shot Sound in C#

6:42 Set Global SoundTags

8:07 Mixing Reflections

8:46 Using the Lowpass Filter

10:00 Using Distortion

10:41 Outro

Sonity - SoundPhysics & Intensity Tutorial

Link to video

0:00 Introduction

1:45 SoundPhysics Basic: Impact and Intensity, Crossfading velocity layers

9:55 SoundPhysics Intermediate: Friction, Exit and OnTrigger

16:56 SoundPhysics Advanced A: Using SoundPhysicsConditions

21:52 SoundPhysics Advanced B: Using SoundTags

32:09 Outro

1.3 Installation

1.  After purchase, go to the Package Manager, show “My Assets” and search for “Sonity”.

2.  Then click on “Sonity” and press “Download”, then “Import”.

3.  It should be located at “Assets\Plugins\Sonity”

Tip:         If you’re upgrading from an earlier version you might need to remove the whole “Sonity” folder in the project.

And if you´re still having trouble, try removing the “.asmdef” files, search for “t:asmdef Sonity.” and then re-import those files again.

Also, if you have your own .asmdef files in your project, you might have to reference both Sonity Runtime .asmdef files to use Sonity.

How to Upgrade Free Trial

Just delete the “Sonity” folder and import the paid version of Sonity, all assets created with the free trial will continue to work.

Supported Unity Versions

Tested, full functionality.

Tested, everything works except “Debug SoundEvents Live (In Scene View)” and Terrain example.

Minor GUI tweaks for compatibility.

Everything works except DSP (distortion/lowpass/highpass).

Disabling Domain Reloading

Adding and deleting SoundEvents in runtime is supported since Sonity 1.0.5.

1.4 Adding the SoundManager

The SoundManager is used to play sounds and manage global settings.

An instance in the scene is required to play SoundEvents.

You can either add the pre-made prefab called “SoundManager” or add the “Sonity - Sound Manager” component to an empty GameObject in the scene.

Tip: Don’t forget to set up the Distance Scale to match the scale of your project.

More info at SoundManager Component.

1.5 Asset Creation

The asset hierarchy for playing sounds is:

AudioClip > SoundContainer > SoundEvent

If you have a bunch of AudioClips in your project, just select them (or their folder).

Then right click to bring up the “Create” > “Sonity” > “Create Assets from Selection” menu and press the desired button.

More info at Create Assets From Selection.

1.6 Asset Editing

The SoundContainers and SoundEvents contain the settings of how your sounds are played.

They are made of scriptable objects, so all changes you make in runtime are updated live and saved.

Tip: All Sonity scriptable objects and components are multi-editable.

SoundContainer Intro

SoundContainers are the building blocks of Sonity.

They contain AudioClips and options of how the sound should be played.

All SoundContainers are multi-object editable.

Overview:

Looping

Volume

Pitch

Spatial Blend

Spatial Spread

Stereo Pan

Reverb Zone Mix

Distortion

Lowpass Filter

Highpass Filter

Tip: Don’t forget to use the presets.

More info at SoundContainer.

SoundEvent Intro

SoundEvents are what you play in Sonity.

They contain SoundContainers and options of how the sound should be played.

All SoundEvents are multi-object editable.

Overview:

Timeline

Modifier volume, pitch, fade in/out, etc.

Intensity.

Trigger another SoundEvent on Play, Stop, Tail, Tag.

More info at SoundEvent.

1.7 Shortcuts

If you import Sonity and the shortcuts don't do anything, go to Edit -> Shortcuts… and Search for Sonity

And assign the shortcuts like in the picture:

Create Assets From Selection Shortcuts

SC+SE from AudioClip Group Multiple SE: Ctrl+Shift+Q

SC+SE from AudioClip Group Single SE: Ctrl+Shift+W

SoundPolyGroup for SE Multiple: Ctrl+Alt+Shift+Q

SoundPolyGroup for SE Single: Ctrl+Alt+Shift+W

They are rebindable in the Shortcuts window.

Preview Shortcuts

Play: Ctrl+Q (Previews the selected SoundEvent or SoundContainer).

Stop: Ctrl+W (Stops any playing preview of SoundEvents and SoundContainers, press two times to skip fade out).

They are rebindable in the Shortcuts window.

Timeline Shortcuts & Controls

Zoom: Mousewheel scroll.

Pan: Mousewheel hold and drag (or left mouse button also if outside of item).

Volume: Hold and drag top of item up/down or click on the volume to write the decibel value.

Move item: Hold and drag on item left/right.

Focus on items: F

1.8 Playing and Stopping Sounds with SoundTrigger Basics

To play a SoundEvent, create a gameobject and add a SoundTrigger component to it.

Then select the SoundEvent you want to play and when you want it to play like in the example below:

More info at SoundTrigger.

1.9 Playing and Stopping Sounds with C# Basics

To play a SoundEvent, create a C# script and include the “Sonity” namespace.

Then make a public “SoundEvent” property, select the desired SoundEvent in the inspector.

Use the functions of the SoundEvent to play and stop your SoundEvents like in the example below:

More info at SoundEvent Functions and the SoundManager Functions.

Example code:

using UnityEngine;
using Sonity;

public class PlayStopExample : MonoBehaviour {

   
public SoundEvent soundEvent;

   
void PlayExample() {
       
// Plays the SoundEvent at the position of the transform
       soundEvent.
Play(transform);
   }

    void StopExample() {
       
// Stops the SoundEvent playing at the transform
       soundEvent.
Stop(transform);
   }
}

1.10 Templates & Examples

Sonity contains examples and script templates of advanced functionality which you can use in your game.

Example_AudioMixerWithLimiter.mixer

Is an AudioMixer which has a limiter on the master so that loud sounds can’t clip over the volume threshold.

TemplateSoundMusicManager.cs

Template of a singleton music playback system.

Add to a GameObject in the scene and use like this:

SonityTemplate.TemplateSoundMusicManager.Instance.PlayMainMenu();

TemplateSoundPlayUI.cs

Template of a singleton used to play e.g. UI sounds.

Useful when you want to play SoundEvents in a lot of places through code.

Add to a GameObject in the scene and use like this:

SonityTemplate.TemplateSoundPlayUI.Instance.PlayButtonClick();

TemplateSoundVolumeManager.cs

Template of a singleton AudioMixer volume controller.

The default settings work with the provided "Example_AudioMixerWithLimiter.mixer".

Add to a GameObject in the scene and use like this:

SonityTemplate.TemplateSoundVolumeManager.Instance.SetVolumeMaster(1f);

1.11 Unity Native Audio Support

Sonity is built around the native audio system in Unity, so everything that Unity audio supports Sonity also supports.

You can use built in features like:

AudioClip

Settings for your audio data.

Tips: Music and longer sounds should probably be set to streaming as to use less memory.

If you have problems with e.g. stuttering audio, try changing the Load Type of the AudioClips.

Read more on: How To - Optimize AudioClip Settings.

AudioMixer

For channel based effects like reverb sends, compression, ducking etc. Contains AudioMixerGroups, which SoundContainers and SoundEvents can be assigned to output into.

Can also expose parameters to enable real time editing of e.g. volume and reverb effects (see for example TemplateSoundVolumeManager).

Performance tips:

If you have issues with audio performance you might want to make sure you’re not using an unnecessary amount of AudioMixerGroups.

Because changing AudioMixerGroup for a Voice uses performance (when playing a new Voice Sonity tries to find an unused Voice which uses the same AudioMixerGroup).

Use AudioMixerGroups when you want effects per group or e.g. ducking or for larger groups of sounds, but maybe not a have a unique one for each sound.

If you need to increase performance, look at SoundMix assets for controlling volume hierarchically.

Audio Mixer Snapshot

For switching between different effect settings in the Audio Mixer.

Reverb Zones

For reverb with different settings in different zones.

Audio Project Settings

For global settings of the audio like Buffer Size (latency), Speaker Mode (5.1, surround etc) and Spatializer Plugin (VR, vertical spatialization, steam audio, oculus/meta spatializer etc).

Tip: If you experience audio performance problems/stutter/dropouts you might want to raise your DSP Buffer Size to Good Latency or Best Performance. And maybe lower the number of voices your project is allocated. 32 Real Voices should be sufficient for most games and you really never need to go above 64 Real Voices in my experience.

Audio Listener

Need to be placed in the scene for audio to be heard. Is usually placed on the main camera or player.

1.12 How To

This section is filled with answers for commonly asked questions.

How To - Optimize AudioClip Settings

Here are some general settings you’d want for most games get lower RAM usage, disk read and CPU usage.

Unity Manual - AudioClip (Read more about the other settings).

AudioClip - Overall Settings

Compression Format:Vorbis

Quality: 60. Which is ~192 kbit/s for Vorbis. You can go lower if you’d want to save space but it comes at a loss of quality.

Sample Rate Setting: Should be the same as the sample rate of the platform, which today mostly is 48kHz (this is so that it doesnt have to do a sample rate conversion) when playing.

Also, if the sounds are created in 48kHz there is more high frequency content which makes it sound better when pitching down vs 44.1kHz.

Tip: If you select multiple AudioClips, you can see their total “Imported Size” which is the size they’ll have after all your format and quality settings are applied.

AudioClip - Vorbis Quality

Unity Vorbis Quality 1 is VBR Quality 0 (not -2). Mono is half the bitrate of stereo and 4 channel files (for surround) are twice the bitrate of stereo.

 Unity

 Vorbis Quality

 VBR Target

 kbit/s stereo

 VBR Target

 kbit/s mono

 VBR Range

 kbit/s stereo

 Noise Test

 kbit/s stereo

 Size %

 vs 100

 Size %

 vs 60

 Comment

 100

 500

 250

 500 - 1000

 554

 100%

 260%

 Uneccessarely big, don’t use this

 90

 320

 160

 320 - 500

 435

 64%

 167%

 Uneccessarely big

 80

 256

 128

 256 - 320

 382

 51%

 133%

 Use if you want to mazimize quality & have the disk space and RAM

 70

 224

 112

 224 - 256

 309

 45%

 117%

 60

 192

 96

 192 - 224

 232

 38%

 100%

 Use this as a default, it is a good balance between quality and size

 50

 160

 80

 160 - 192

 173

 32%

 83%

 Sounds like near CD quality

 40

 128

 64

 128 - 160

 128

 26%

 67%

 30

 112

 56

 112 - 128

 117

 22%

 58%

 Smaller & better sound than .mp3 128kbps

 20

 96

 48

 96 - 112

 102

 19%

 50%

 10

 80

 40

 80 - 96

 87

 16%

 42%

 Sounds acceptable. Use if you are desparate for saving space and RAM

 1

 64

 32

 64 - 80

 71

 13%

 33%

 Looses a lot of quality, noticeably stereo separation and bass

Notes: Noise test is calculated using VBR export & size comparison to CBR with a known bitrate.

Sources: Recommended Encoder Settings and Vorbis Quality. The bitrates are approximate.

AudioClip - Load Type

Stereo files are double the size of mono files. So a 60s 2 channel sound is the same size as a 120s 1 channel sound. The lengths are approximated with stereo files in mind.

 Length Seconds ~

 Play Frequency

 Load Type

 Pros

 Cons

 Example Sounds

 Short - Less than 1s

 High

 Decompress On Load

 Uses less CPU

 Uses 10x RAM so only use for short sounds.

 Player sounds, footsteps, impacts etc

 Commonly used for mobile platforms

 Short - Less than 1s

 Low

 Compressed In Memory

 Uses less RAM

 

 Medium - More than 1s

 less than 60s

 High & Low

 Compressed In Memory

 Uses less RAM

 Long  - More than 60s

 High

 Compressed In Memory

 Uses less disk read

 Try if you have problems with audio delays

 Watch out for load times and RAM usage

 Localized 3D ambiences etc

 Long  - More than 60s

 Low

 Streaming

 Uses less RAM

 Many platforms can only handle less than

 10 simultaneously streaming sounds

 Music, background 2D ambiences etc

Note: You want to stream the largest files you have, but not too many at the same time.

So the 60s threshold for long sounds can be lowered to e.g. 30s or even lower if not many sounds are +60s.

AudioClip - Preload Audio Data

Makes the sound load at startup, which might create long load times on harddrives and slower systems.

Is useful to combine with Load In Background so it doesn’t interrupt the main thread.

 Length in seconds

 Play Frequency

Preload Audio Data

 Pros

 Cons

 Example Sounds

 Short - Less than 1s

 High

 Yes

 Less frequent disk read

 Use only for frequent & short sounds

 Combine with Load in Background

 Player sounds, footsteps, impacts etc

 Short - Less than 1s

 Low

 No

 Medium & Long - More than 1s

 Low

 No

 

Note: I’ve had problems where if I don’t Preload Audio Data, there might be clicks heard in the end of sounds.

"Prevent End Clicks" in the SoundContainer mitigates this.

AudioClip - Load In Background

When enabled, the AudioClip is loaded without stalling the main thread and any playing is delayed until the AudioClip is loaded.

Useful to combine with Preload Audio Data so it doesn’t interrupt the main thread.

How To - Debug Sounds and Performance

If you want to debug audio performance or what sounds are playing, you can use:

- Unity built in Profiler

- SoundManager Statistics

Unity Profiler

Read more here.

Because Sonity is built upon Unity native AudioSources, you can use the built in Profiler.

Example picture of the audio part of the profiler with “Deep Profile” enabled:

SoundManager Statistics

Read more here.

Example picture of the the SoundManager.

How To - Rename A Lot of Assets

If you need to rename a lof of assets in Unity I can recommend the free tool called “Mulligan Renamer”.

Download at Unity Asset Store or Github.

Example of use:

How To - Force Resave Assets

If you want to force save all changes for any assets in Unity, you can use the tool "Set Selected Assets as Dirty (Force Reserialize for Resave)".

1.13 Sonity Changelog

Here is a list of all the changes made to each released version of Sonity.

1.0.5

New Tutorial: SoundPhysics & Intensity Tutorial (https://youtu.be/ehnwL678N4E)

New Feature: Support for Adressables (deleting SoundEvents in runtime).

New Feature: SoundPhysics is expanded with support for Is Trigger and exit sounds.

New Feature: New SoundPhysicsConditions object for advanced reusable conditions and terrain layer support.

New Feature: Added a SoundPreset object enabling custom presets for SoundEvents and SoundContainers.

New Feature: Added Pause/Unpause functions e.g. Pause/Unpause AllAtOwner, Everywhere, Everything, 2D, All2D, Music, AllMusic.

New Feature: Added SoundManager functions and settings Global Pause and Global Volume.

New Feature: Added SoundManager setting for Sound Time Scale and default is changed from RealtimeSinceStartup to UnscaledTime.

New Feature: Added SoundEvent settings Ignore Local Pause and Ignore Global Pause.

New Feature: Added GetMusic and Get2D functions like e.g. GetMusicSoundEventState().

New Feature: Better UnityEvent support by adding SoundEvent functions with less parameters like "StopAllowFadeOut and StopImmediate etc.

Deprication: SoundPhysics is reworked with arrays of SoundEvents, automatic conversion system is added in the editor.

Deprication: SoundPhysics is reworked to use object references so old tags must be remade.

Documentation how to: Added How To - Optimize AudioClip Settings.

Documentation how to: Added How To - Rename A Lot of Assets.

Documentation how to: Added How To - Debug Sounds and Performance.

Documentation: Added video tutorial links.

Documentation: Documented SoundTrigger and SoundPicker functions.

Documentation: Updated info on AudioMixerGroup performance tips.

Change: SoundPhysics is split for performance reasons into SoundPhysics, SoundPhysics2D, SoundPhysicsNoFriction, SoundPhysics2DNoFriciton.

Change: Renamed SoundTrigger enum StopNoFadeOut to StopImmediate.

Change: Renamed StopAllAt2D() to StopAll2D().

Change: Renamed tools and create assets to "Sonity 🔊".

Change: Renamed GetLastPlayedClipTime() to GetLastPlayedClipTimeSeconds.

Addition: Added GetLastPlayedClipTimeRatio().

Addition: Added SoundTrigger Actions: Pause, Pause Forced, Unpause.

Addition: Added SoundEventState.Paused.

Addition: Added SoundPhysics example scenes including friction, exit, Trigger On etc.

Addition: Added Intensity Scale Add and Scale Multiplier and Scale Max to 1 button.

Addition: Added Intensity Debug Zoom for easier visual debugging.

Addition: Added Tools "Set Selected Assets as Dirty (Force Reserialize for Resave)".

Addition: Expanded Example_AudioMixerWithLimiter with AMB, MUS, SFX, UI, VO.

Fix: SoundContainer distance scale is hidden when distance is disabled.

Fix: Increased the contrast of the SoundEvent and SoundContainer icons.

Fix: Fixed so automatic crossfades work with sound names ending with "loop".

Fix: Fixed SoundParameterIntensity continuous threshold stopping sounds and restarting loops.

Fix: Fixed problem where SoundPhysics friction didnt work as expected.

Fix: Fixed bug where SoundParameters weren't nullchecked.

Fix: Fixed so SoundContainer volume can be increased when multiple objects are selected and volume is at -0 dB.

Fix: Optimized SoundEvent recorded intensity drawing.

Fix: Replaced all ToLower with ToLowerInvariant for greater language support.

Fix: Fixed bug with create assets filename extension.

Fix: Fixed nullcheck in SoundPicker for SoundManager.Instance.

Legacy support: Fixed Unity 2018 compability by fixing: asmdef to non guid mode, SubsystemRegistration, GetContact.impulse, editor enum and header names.

1.0.4

Free trial version released.

Please remove the whole Sonity folder before upgrading because scripts were moved.

Fixed bug where audio positions were based on the previous frame.

Fixed bug where disabled SoundEvents played in builds.

Fixed scripts for free trial version.

1.0.3

New feature: Support for disabling domain reloading in the “enter play mode options”.

New feature: Override Listener Distance with the AudioListenerDistance component.

Parented all Sonity scene objects created in runtime under the SoundManager.

Improved documentation on how to bind shortcuts.

Fixed SoundTriggerCustomEditor example code.

Fixed preview TriggerOnTail tail length 0 bug.

1.0.2.1

Hotfix: Fixed error in SoundContainer settings editor.

1.0.2

Please remove the whole Sonity folder before upgrading because folders were moved.

New feature: Pass Parameter setting in the SoundEvent for passing SoundParameters to sub SoundEvents.

New feature: Added GetSpectrumData() to get the spectrum data from AudioSources.

Added support for using multiple disabled AudioListeners.

Added support for SoundTrigger Custom Override and added examples in the documentation.

Fixed support in examples and the timeline for the new Input System Package.

Added tips and info about "Unity Native Audio Support" in documentation.

Fixed bug where SoundEvents with global polyphony couldn't be stopped.

Fixed nullcheck in SoundPicker for SoundManager.Instance.

The SoundManager and sub objects are now moved to Vector3.zero at start.

Added example scene showcasing SoundPicker.

SoundPhysics added info about rigidbody requirements.

SoundPhysics removed collider requirement warning.

Updated asmdef info in documentation.

Preparing code for trial DLL version.

Fixed documentation SoundParameter incorrect example code.

Fixed Find Assets OrderBy bug.

Fixed DontDestroyOnLoad tooltip.

Fixed Modifier tooltips.

Fixed SoundParameterIntensity summary.

Fixed Play2D summary.

1.0.1

Please remove the whole Sonity folder before upgrading because folders were moved.

New feature: Automatic asset creator finds common denominator name.

New feature: SoundContainer presets added set automatic looping and automatic crossfades.

Added new examples used in the new gun tutorials.

Updated documentation.

Fixed bug with serialized cache bools.

Fixed bug with SoundTag position.

Fixed bug with preview SoundEvent distance scale.

Fixed so debug logs only print in developent builds and the editor.

Fixed nullcheck for camera in "Debug SoundEvents Live in Game View".

Changed so timeline zooms when holding down control and scrolling with mousewheel.

Changed so SoundEvent SoundTag always use modifiers.

Trigger on tail default length changed to 0.

Trigger on tail added warning if length is less than shortest AudioClip.

SoundEvent and SoundManager GetMaxLength removed forceUpdate.

All helpboxes now respect GUI Warnings setting.

Optimized SoundManager update.

Minor spelling corrections of tooltips and documentation.

Cleared SoundEventInstanceDictionaryValue.cs

Changed template scripts to useDontDestroyOnLoad to public.

1.0.0

Release.

2 Create Assets From Selection

Right-click in the project menu to bring up the “Create Assets from Selection” menu.

With this you can easily create all your sound assets quickly if your AudioClips are named right.

Shortcuts

SC+SE from AudioClip Group Multiple SE: Ctrl+Shift+Q

SC+SE from AudioClip Group Single SE: Ctrl+Shift+W

SoundPolyGroup for SE Multiple: Ctrl+Alt+Shift+Q

SoundPolyGroup for SE Single: Ctrl+Alt+Shift+W

They are rebindable in the Shortcuts window.

AudioClip Group

AudioClip groups are sounds with the same name, but different numbers in the end e.g 01, 02, 03 etc.

Create SoundContainers and multiple SoundEvents

In this example we select the bow and drill sounds and run “SC+SE from AudioClip Group Multiple SE”:

This creates 4 SoundContainers and 4 SoundEvents, one per AudioClip group.

Create SoundContainers and a single SoundEvent

In this example we select the shoot sounds and run “SC+SE from AudioClip Group Single SE”:

They contain 4 different groups which will create 4 SoundContainers, one per group and a single SoundEvent.

It will try to find a common denominator of the names of the SoundContainers for naming the SoundEvent.

3 SoundContainer

SoundContainers are the building blocks of Sonity.

They contain AudioClips and options of how the sound should be played.

All SoundContainers are multi-object editable.

Here is a description of controls shared by multiple fields.

Rolloff

The power of the rolloff.

0 is linear.

Curve

Curve of the value over distance or intensity.

Distance: From 0 (close) to 1 (distant).

Intensity: From 0 (soft) to 1 (hard).

Strength

How much effect the distance/intensity should have.

Increase

Increases the amount.

3.1 SoundContainer Presets

The “Presets” shown in the example picture above need to be created with the SoundPreset object.

This info also shows up on button hover:

SFX 3D

Enable Distance = true

Spatial Blend = 1

Never Steal Voice = false

Never Steal Voice Effects = false

Pitch Random = true

Priority = 0.5

SFX 2D

Enable Distance = false

Spatial Blend = 0

Never Steal Voice = false

Never Steal Voice Effects = false

Pitch Random = true

Priority = 0.5

Music

Enable Distance = false

Spatial Blend = 0

Never Steal Voice = true

Never Steal Voice Effects = true

Pitch Random = false

Volume Random = false

Priority = 1

Automatic Looping

If the name of the selected SoundContainers contains “loop” then it will automatically enable “Loop”, “Follow Position”, “Stop if Transform is Null” and “Random Start Position”.

Automatic Crossfades

If the names of the selected SoundContainers end in certain combinations it will automatically set up distance or intensity crossfades.

It works on multiple groups at the same time.

These are the combinations and their result:

Distance Crossfade:

Close + Distant + Far = 3 layers

Close + Distant = 2 layers

Close + Far” = 2 layers

Intensity Crossfade:

Soft + Medium + Hard = 3 layers

Soft + Hard = 2 layers

Example usage of Automatic Crossfades:

SoundPresets

Create SoundPreset objects to get custom settings which you can apply to your SoundContainers and SoundEvents.

Either manually select the preset you want to apply in the dropdown, or use “Auto Match” to automatically apply the settings based on the name of the asset.

3.2 SoundContainer Preview

With the preview you can listen to the sounds in the editor.

The preview handle enables you to move the sound around.

Preview Shortcuts

Play: Ctrl+Q (Previews the selected SoundEvent or SoundContainer).

Stop: Ctrl+W (Stops any playing preview of SoundEvents and SoundContainers, press two times to skip fade out).

They are rebindable in the Shortcuts window.

Play

Previews the SoundContainer.

Does not work if Unity cannot build the project, or if the game is paused.

The default shortcut is Ctrl+Q.

Stop

Press two times to skip fade out.

The default shortcut is Ctrl+W.

Reset

Resets the preview settings.

Intensity

Controls the intensity value of the played SoundContainers.

AudioMixerGroup

Only used for preview.

3.3 SoundContainer AudioClips

This is where you assign the AudioClips which are going to be used when the SoundContainer is played.

Update AudioClips

Updating AudioClips can be used to automatically add/remove variations.

Can be used on multiple items at once (tip: search “t:soundContainer”).

Refresh AudioClip Group

Adds all AudioClips with the same name as the first AudioClip (disregarding numbers, e.g. 01 02).

Find AudioClip Group

Automatically finds all AudioClips containing the same name as this SoundContainer (disregarding _SC, numbers).

If no matching AudioClips are found, it will try and remove one character at the end of the name at a time until it finds a hit.

Drop AudioClips/Folders Here

Here you can drag and drop AudioClips or folders with AudioClips in them.

3.4 SoundContainer Settings

Tip: All the info is also available as tooltips if you hover over properties.

AudioMixerGroup

The AudioMixerGroup you want to output to.

The SoundEvents AudioMixerGroup overrides the SoundContainers AudioMixerGroup.

Performance tips:

If you have issues with audio performance you might want to make sure you’re not using an unnecessary amount of AudioMixerGroups.

Because changing AudioMixerGroup for a Voice uses performance (when playing a new Voice Sonity tries to find an unused Voice which uses the same AudioMixerGroup).

Use AudioMixerGroups when you want effects per group or e.g. ducking or for larger groups of sounds, but maybe not a have a unique one for each sound.

If you need to increase performance, look at SoundMix assets for controlling volume hierarchically.

Enable Distance

Otherwise the SoundContainer will not be affected by distance (disable for music etc).

Distance Scale

Range scale multiplier. It is multiplied by the Distance Scale of the SoundManager.

Loop

Makes the sound loop.

If you use "Create Assets from Selection"  and the AudioClip name contains "loop".

Then it will automatically enable “Loop”, “Follow Position”, “Stop if Transform is Null” and “Random Start Position”.

Follow Position

If the SoundContainer should follow the given Transform position.

Stop if Transform is Null

Automatically stops the sound if the Transform it's played at is destroyed (either the owner or position Transform).

Useful safety precaution for loops.

Random Start Position

Starts the sound at a random position.

Overrides the Start Position setting.

Useful for loops.

Random Range

Min/max range within the sound can start at.

Start Position

0 is the start and 1 is the end.

Reverse

If enabled the AudioClip will be played backwards.

Make sure to set the start position to the end.

Reverse is only supported for AudioClips which are stored in an uncompressed format or will be decompressed at load time.

Lock Axis

Locks the selected axis to the selected position.

Useful for 2D games if you want to lock the sound to a position along an axis.

Axis

The axis to lock.

Position

The position to set the locked axis to.

Advanced

Play Order

Determines in which order the AudioClips will be played.

Global Random

All SoundEvents will share the same global random AudioClip pool, which ensures less repetition.

Uses a pseudo random function remembering half of the length of available AudioClips it last played to avoid repetition.

Local Random

Same as global random except its per SoundEvent owner.

If enabled all will share the same global random AudioClip pool, which ensures less repetition.

Otherwise random AudioClip per owner is used.

The randomizer either way uses a pseudo random function remembering which AudioClips it last played to avoid repetition.

Priority

The priority the Voice has when Voice stealing.

Also the priority the Voice Effects has when Voice Effects stealing.

1 is high priority, 0.5 is default priority and 0 is low priority.

It's multiplied with the volume of the Voice when evaluating final priority.

Prevent End Clicks

If enabled it will fade out the volume 0.1 seconds before the end of the AudioClip to prevent clicks.

If the AudioClips is shorter than 0.1 seconds or set to loop the fade will be skipped.

DC offsets and some settings in Unity make an AudioClip click at the end.

Tip: If you still experience sporadic clicks, try changing the Load Type of the AudioClips to e.g. "Compressed In Memory", it might help.

Never Steal Voice

The SoundManager will never steal this Voice if the Voice Limit is reached (use on music etc).

Never Steal Voice Effects

The SoundManager will never steal the Voice Effects on this Voice if the Voice Effect Limit is reached (use on music etc).

Doppler Amount

How much the pitch of the sound is changed by the relative velocity between the AudioListener and the AudioSource.

Bypass Reverb Zones

Bypasses any reverb zones

Bypass Voice Effects

Bypasses any effects on the AudioSource, e.g. Distortion and Filters.

Voice effects are automatically bypassed if you don't have distortion/lowpass/highpass enabled.

Bypass Listener Effects

Bypasses any effects on the listener

3.5 SoundContainer Volume

Controls the volume (in decibel).

Tip: If you want to be able to raise the volume and not just lower it, select all the SoundContainers and lower the volume to -12 dB.

Then to compensate you can increase the global volume with an Audio Mixer (which you then can set to +12 dB).

-1 dB

Lowers the relative volume of all the selected SoundContainers.

Useful for example if you want to raise the volume of one SoundContainer and keep the relative volume.

Because then you can lower all of them to get more headroom.

If multiple SoundContainers are selected it will show the lowest volume.

+1 dB

Raises the relative volume of all the selected SoundContainers.

Stops if any of the selected SoundContainer reaches 0 db.

Useful for example if you want to set the loudest volume to 0 dB but keep the relative volumes.

If multiple SoundContainers are selected it will show the highest volume.

Distance Crossfade

With distance crossfade you can easily crossfade between different sounds over distance.

For e.g. gunshots you could add sounds with close, distant and far perspectives.

You’d set the “Layers” setting to 3 for all the SoundContainers.

Then you’d set “This Is” of close to 1, distant to 2 and far to 3.

Layers

The number of layers the crossfade is based on. You must have at least 2 layers.

This is

Which layer this is. Set up with other SoundContainers for the other layers. Lower numbers are closer and higher are more distant.

Intensity

Changes the volume over intensity.

Use on for example physics sounds where you pass the velocity with a SoundParameterIntensity.

Intensity Crossfade

With intensity crossfade you can easily crossfade between different sounds over intensity.

For e.g. impacts you could add sounds with hard, medium and soft variations.

You’d set the “Layers” setting to 3 for all the SoundContainers.

Then you’d set “This Is” of hard to 3, medium to 2 and soft to 1.

Layers

The number of layers the crossfade is based on. You must have at least 2 layers.

This is

Which layer this is. Set up with other SoundContainers for the other layers. Higher numbers are harder and lower numbers are softer.

Intensity Crossfade example:

3.6 SoundContainer Pitch

Controls the pitch (in semitones).

Intensity

Changes the pitch over intensity.

Use on for example car sounds where you pass the speed with a SoundParameterIntensity.

Low st

The lowest intensity in semitones. Range -128 to 128.

High st

The highest intensity in semitones. Range -128 to 128.

3.7 SoundContainer Spatial Blend

Controls the spatial blend. 0 is 2D (not spatialized) and 1 is 3D (spatialized).

Intensity

Changes the spatial blend over intensity.

3.8 SoundContainer Spatial Spread

Controls the spatial spread (in degrees).

Only the 3D (spatialized) part of the sound is affected by the spatial spread.

Intensity

Changes the spatial spread over intensity.

3.9 SoundContainer Stereo Pan

Controls the stereo pan. -1 is left and 1 right.

Only the 2D part of the sound is affected by the stereo pan.

Angle To Stereo Pan

Pans the sound depending on the angle between the Voice and the AudioListener.

3.10 SoundContainer Reverb Zone Mix

Controls the reverb zone mix (in decibel).

Intensity

Changes the reverb zone mix over intensity.

3.11 SoundContainer Distortion

Waveshaper type distortion.

0 is clean, 1 is distorted.

SoundContainer Voice Effects are applied per Voice.

If distortion amount is 0 the effect is disabled internally for performance.

The number of active Voice Effects are limited by the “Voice Effect Limit” on the SoundManager.

DSP effects are not available in WebGL.

Intensity

Changes the distortion over intensity.

Use on for example explosion sounds where you pass the size of the explosion with a SoundParameterIntensity.

3.12 SoundContainer Lowpass

Lowpass filter with a variable amount.

Maximum of 6dB per octave.

SoundContainer Voice Effects are applied per Voice.

If frequency is 20,000 Hz or amount is 0 dB the effect is disabled internally for performance.

The number of active Voice Effects are limited by the “Voice Effect Limit” on the SoundManager.

DSP effects are not available in WebGL.

Intensity

Changes the lowpass over intensity.

Use on for example occluded sounds where you pass the amount of occlusion with SoundParameterIntensity.

3.13 SoundContainer Highpass

Highpass filter with a variable amount.

Maximum of 6dB per octave.

SoundContainer Voice Effects are applied per Voice.

If frequency is 20 Hz or amount is 0 dB the effect is disabled internally for performance.

The number of active Voice Effects are limited by the “Voice Effect Limit” on the SoundManager.

DSP effects are not available in WebGL.

Intensity

Changes the highpass over intensity.

Use on for example occluded sounds where you pass the amount of occlusion with SoundParameterIntensity

3.14 SoundContainer Find References

Find References

Finds all the references to the SoundContainer.

Select All

Selects all the assets with references to the SoundContainer.

Clear

Removes all the found references.

4 SoundEvent

SoundEvents are what you play in Sonity.

They contain SoundContainers and options of how the sound should be played.

All SoundEvents are multi-object editable.

4.1 SoundEvent Presets

The “Presets” shown in the example picture above need to be created with the SoundPreset object.

SoundPresets

Create SoundPreset objects to get custom settings which you can apply to your SoundContainers and SoundEvents.

Either manually select the preset you want to apply in the dropdown, or use “Auto Match” to automatically apply the settings based on the name of the asset.

4.2 SoundEvent Mute, Solo, Disable

Mute

Mutes the SoundEvent.

Only affects the Unity Editor.

Solo

Mutes all other SoundEvents who don't have solo enabled.

The Solo property is not serialized (e.g. will be reset on start).

This is to prevent leaving a SoundEvent soloed by mistake which would make nothing else sound when the game runs.

Only affects the Unity Editor.

Disable

Disables the playing of the SoundEvent.

It is also disabled when building the project.

4.3 SoundEvent Preview

With the preview you can listen to the sounds in the editor.

The preview handle enables you to move the sound around.

Preview Shortcuts

Play: Ctrl+Q (Previews the selected SoundEvent or SoundContainer).

Stop: Ctrl+W (Stops any playing preview of SoundEvents and SoundContainers, press two times to skip fade out).

They are rebindable in the Shortcuts window.

Play

Previews the SoundEvent.

Does not work if Unity cannot build the project, or if the game is paused.

Preview doesn't play more than one level of TriggerOnPlay/Stop/Tail at the moment (there is full functionality ingame).

The default shortcut is Ctrl+Q.

Stop

Press two times to skip the fade out.

The default shortcut is Ctrl+W.

Reset

Resets the preview settings.

Intensity

Controls the intensity value of the played SoundContainers.

AudioMixerGroup

Only used for preview.

4.4 SoundEvent SoundContainers

This is where you assign the SoundContainers which are going to be used when the SoundEvent is played.

Find SoundContainers

Automatically finds all SoundContainers containing the same name as this SoundEvent (disregarding _SE, numbers).

Can be used on multiple items at once (tip: search "t:soundEvent").

If no matching SoundContainers are found, it will try and remove one character at the end of the name at a time until it finds a hit.";

Drop SoundContainers/Folders Here

Here you can drag and drop SoundContainers or folders with SoundContainers in them.

4.5 SoundEvent Timeline

In the timeline editor you can move the items in time and change the volume volume of individual SoundContainers.

The length of the item in the timeline is determined by the length of the longest AudioClip in the SoundContainer.

If you change the pitch, the length of the item will match the pitch.

Shortcuts and Controls

Zoom: Ctrl + mouse wheel scroll.

Pan: Mouse wheel hold and drag (or left mouse button hold and drag on the background).

Volume: Hold and drag top of item up/down or click on the volume to write the decibel value.

Move item: Hold and drag on item left/right.

Focus on items: F

4.6 SoundEvent Modifiers

Modifiers are used to control how SoundEvents are played (e.g. volume, polyphony, fade in length etc).

See Modifiers for more info.

4.7 SoundEvent Settings

Polyphony Mode

Limited Per Owner:

Useful if you want to limit polyphony e.g per player.

You can use e.g SoundEvent.PlayAtPosition(); to play a SoundEvent at one position with another owner.

Limited Globally:

Useful if you want to limit the polyphony globally e.g for bullet impacts.

This setting will change the old owner to the new position and set the new owner as the Transform of the SoundManager.Instance.

Tip: If you want to limit the polyphony per owner and globally at the same time, you can use SoundPolyGroups.

AudioMixerGroup

The AudioMixerGroup you want to output to.

The SoundEvents AudioMixerGroup overrides the SoundContainers AudioMixerGroup.

Performance tips:

If you have issues with audio performance you might want to make sure you’re not using an unnecessary amount of AudioMixerGroups.

Because changing AudioMixerGroup for a Voice uses performance (when playing a new Voice Sonity tries to find an unused Voice which uses the same AudioMixerGroup).

Use AudioMixerGroups when you want effects per group or e.g. ducking or for larger groups of sounds, but maybe not a have a unique one for each sound.

If you need to increase performance, look at SoundMix assets for controlling volume hierarchically.

SoundMix

SoundMix enables hierarchical control of for example volume.

SoundPolyGroup

SoundPolyGroup gives polyphony control grouped over different SoundEvent types.

Priority

Lower priority SoundEvents will be stolen first.

If "Skip Lower Priority" is enabled on the SoundPolyGroup this will determine if this SoundEvent will play or not when the Polyphony Limit is reached.

Cooldown Time

How quick this SoundEvent can be retriggered in seconds.

Is calculated using the time scale selected in the SoundManager.

Probability %

The probability that this SoundEvent should play.

Pass Parameters

If SoundParameters should be passed to sub.

E.g SoundTag, TriggerOnPlay, TriggerOnStop, TriggerOnTail.

Ignore Local Pause

If enabled, the SoundEvent won't be paused unless force pause is used.

Ignore Global Pause

If enabled, the SoundEvent won't be paused when global pause is used.

4.8 SoundEvent Intensity

Intensity contains settings for how SoundParameterIntensity is scaled before it is applied to the enabled intensity options e.g Volume, Pitch etc.

In the example above the sound is played a few times with a SoundParameterIntensity.

The range of the recorded intensity is from 0.5 to 2.5.

When “Scale Min-Max to 0-1” is pressed the following happens:

  1. It first finds the Min value which is 0.5 and sets Add to -0.5 so it is 0
  2. Then it finds the Max value which now is 2 and sets Multiplier to 0.5 so it is 1

This makes the range into 0 to 1.

The intensity debug log records all intensity values used when this SoundEvent is played.

It is used to scale the SoundParameterIntensity to a 0-1 range.

Add

Adds to the SoundParameterIntensity.

Multiplier

Multiplier of the SoundParameterIntensity.

Curve

Curve of the intensity

From 0 (soft) to 1 (hard).

Smoothing

The seek time of the SoundParameterIntensity in seconds.

Is calculated using the time scale selected in the SoundManager.

Enable Threshold

If this SoundEvent is played with a SoundParameterIntensity and it is under the threshold it won't be played.

Threshold

The threshold limit after scaling the intensity value.

Scale Add

Adds to the SoundParameterIntensity, used by the automatic scaling.

Is separate from the manual add setting to provide finer control and better multi-editing.

Scale Multiplier

Multiplier of the SoundParameterIntensity, used by the automatic scaling.

Is separate from the manual multiplier setting to provide finer control and better multi-editing.

Intensity Record

If enabled it will record all SoundParameterIntensity used when playing this SoundEvent.

Debug Zoom

Focuses the vertical zoom scale to the values which are within the min and max range.

Debug Resolution

The resolution of the displayed values.

Scale Max to 1

Sets Intensity Add to 0.

Then uses the recorded values to scale the Max value to 1 with Intensity Multiply.

Useful for e.g. impacts where the Min value is 0 and the Max value is unknown.

Scale Min-Max to 0-1

Uses the recorded values to make the Min value 0 with Intensity Add.

Then uses the recorded values to scale the Max value to 1 with Intensity Multiply.

Useful where Min and Max Intensity value ranges are unknown.

4.9 SoundEvent Trigger On Which to Play

Which to Play

If Play All is selected, then all assigned SoundEvents will be played.

If One Random is selected, then one random of the assigned SoundEvents will be played.

The randomizer uses a pseudo random function remembering which SoundEvents it last played to avoid repetition.

4.10 SoundEvent Trigger On Play

Triggers another SoundEvent when this SoundEvent is played.

4.11 SoundEvent Trigger On Stop

Triggers another SoundEvent when this SoundEvent is stopped.

4.12 SoundEvent Trigger On Tail

Triggers another SoundEvent "Tail Length" before the end.

It looks at the time of the last played voice on the first SoundContainer.

Useful for music, e.g. if you have an intro with a 2 second tail and a loop you want to play on the tail of the intro.

If you play with SoundManager.PlayMusic, you can stop the next SoundEvent with SoundManager.StopAllMusic without a reference.

If you want it to trigger itself, make sure to set the "Settings" polyphony to 2.

If the trigger timing is not tight enough, try setting the AudioClip "Compression Format" to PCM or ADPCM (Vorbis is less accurate).

Tail Length

How long in seconds before the end of the SoundEvent to trigger the next SoundEvent.

It looks at the time of the last played voice on the first SoundContainer.

It takes into account pitch when calculating time.

For example, if the tail length is 2 seconds and you pitch it +12 semitones (2x speed) the internal tail length will be 1 seconds.

This is because double the speed with half the duration and vice versa.

Set Tail Length from BPM & Beats

Calculates the Tail Length from the BPM and the Beats settings.

BPM

Beats per minute.

Beats

How long the tail is in beats.

4.13 SoundEvent SoundTag

Uses SoundTag to play other SoundEvents and/or change SoundEventModifier.

The SoundTag won't be passed to the SoundEvents of the SoundTag in order to avoid infinite repetitions.

Mode

If local SoundTag is selected you need to pass an SoundTag when playing the SoundEvent.

If global SoundTag is selected you need to set the SoundTag on the SoundManager.

SoundTag

If this SoundTag is selected the SoundEvents below will be played.

Modifiers

If enabled the selected modifiers will be applied to the base SoundEvent and the SoundEvents of the SoundTag.

Modifiers are used to control how SoundEvents are played (e.g. volume, polyphony, fade in length etc).

See Modifiers for more info.

4.14 SoundEvent Find References

Find References

Finds all the references to the SoundEvent.

Select All

Selects all the assets with references to the SoundEvent.

Clear

Removes all the found references.

5 SoundEvent Functions

The SoundEvent can be played directly from itself instead of playing via the SoundManager.

A SoundManager instance in the scene is required to play SoundEvents.

Example code:

using UnityEngine;
using Sonity;

public class PlayStopExample : MonoBehaviour {

   
public SoundEvent soundEvent;

   
void PlayExample() {
       
// Plays the SoundEvent at the position of the transform
       soundEvent.
Play(transform);
   }

    void StopExample() {
       
// Stops the SoundEvent playing at the transform
       soundEvent.
Stop(transform);
   }
}

5.1 SoundEvent Play

// Plays the SoundEvent at the position of the owner Transform

public void Play(Transform owner)
public void Play(Transform owner, SoundTag localSoundTag)
public void Play(Transform owner, params SoundParameterInternals[] soundParameterInternals)
public void Play(Transform owner, SoundTag localSoundTag, params SoundParameterInternals[] soundParameterInternals)

Parameters

owner

The owner Transform

localSoundTag

The SoundTag which will determine the Local SoundTag of the SoundEvent

soundParameterInternals

For example SoundParameterVolumeDecibel is used to modify how the SoundEvent is played

5.2 SoundEvent PlayAtPosition

// Plays the SoundEvent at the Vector3 position with another Transform as the owner

public void PlayAtPosition(Transform owner, Vector3 position)
public void PlayAtPosition(Transform owner, Vector3 position, SoundTag localSoundTag)
public void PlayAtPosition(Transform owner, Vector3 position, params SoundParameterInternals[] soundParameterInternals)
public void PlayAtPosition(Transform owner, Vector3 position, SoundTag localSoundTag, params SoundParameterInternals[] soundParameterInternals)

// Plays the SoundEvent at the Transform position with another Transform as the owner

public void PlayAtPosition(Transform owner, Transform position)
public void PlayAtPosition(Transform owner, Transform position, SoundTag localSoundTag)
public void PlayAtPosition(Transform owner, Transform position, params SoundParameterInternals[] soundParameterInternals)
public void PlayAtPosition(Transform owner, Transform position, SoundTag localSoundTag, params SoundParameterInternals[] soundParameterInternals)

Parameters

owner

The owner Transform

position

The Transform or Vector3 where is should play at (Transform can follow position)

localSoundTag

The SoundTag which will determine the Local SoundTag of the SoundEvent

soundParameterInternals

For example SoundParameterVolumeDecibel is used to modify how the SoundEvent is played

5.3 SoundEvent Stop

Tip: You really only need to use stop for looping or longer oneshot sounds (or the SoundContainer “Stop if Transform is Null” setting).

Use the polyphony setting in the SoundEvent to manage the number of instances playing.

// Stops the SoundEvent at the owner Transform

public void Stop(Transform owner, bool allowFadeOut = true)

// Stops the SoundEvent at the position Transform

public void StopAtPosition(Transform position, bool allowFadeOut = true)

// Stops all the SoundEvents at the owner Transform

public void StopAllAtOwner(Transform owner, bool allowFadeOut = true)

// Stops the SoundEvent everywhere

public void StopEverywhere(bool allowFadeOut = true)

// Stops all SoundEvents

public void StopEverything(bool allowFadeOut = true)

// Stop allowing fade out (Useful for UnityEvents because it only has one parameter)

public void StopAllowFadeOut(Transform owner)

public void StopAtPositionAllowFadeOut(Transform position)

public void StopAllAtOwnerAllowFadeOut(Transform owner)

// Stop without fade out (Useful for UnityEvents because it only has one parameter)

public void StopImmediate(Transform owner)

public void StopAtPositionImmediate(Transform position)

public void StopAllAtOwnerImmediate(Transform owner)

Parameters

owner

The owner Transform

position

The position Transform

allowFadeOut

If the SoundEvent should be allowed to fade out. Otherwise it is going to be stopped immediately

5.4 SoundEvent Pause and Unpause

// Pauses/unpauses the SoundEvent with the owner Transform locally

public void Pause(Transform owner, bool forcePause = false)

public void Unpause(Transform owner)

// Pauses/unpauses all SoundEvents with the owner Transform locally

public void PauseAllAtOwner(bool forcePause = false)

public void UnpauseAllAtOwner()

// Pauses/unpauses the SoundEvent everywhere locally

public void PauseEverywhere(bool forcePause = false)

public void UnpauseEverywhere()

// Pauses/unpauses the SoundEvent everywhere locally

public void PauseEverything(bool forcePause = false)

public void UnpauseEverything()

Parameters

owner

The owner Transform

forcePause

If the SoundEvent should be paused even if it is set to "Ignore Local Pause"

5.5 SoundEvent Get State, Length and Time

// If playing it returns SoundEventState.Playing

// If paused either locally or globally it returns SoundEventState.Paused

// If not playing, but it is delayed it returns SoundEventState.Delayed

// If not playing and it is not delayed it returns SoundEventState.NotPlaying

// If the SoundEvent or Transform is null it returns SoundEventState.NotPlaying

public SoundEventState GetSoundEventState(Transform owner)

// Returns the length (in seconds) of the AudioClip in the last played AudioSource

// Returns 0 if the InstanceSoundEvent is not playing

// Returns 0 if the SoundEvent or Transform is null

// pitchSpeed determines if it should be scaled by pitch. E.g. -12 semitones will be twice as long

public float GetLastPlayedClipLength(Transform owner, bool pitchSpeed)

// Returns the current time (in seconds) of the AudioClip in the last played AudioSource

// Returns 0 if the InstanceSoundEvent is not playing

// Returns 0 if the SoundEvent or Transform is null

// pitchSpeed determines if it should be scaled by pitch. E.g. -12 semitones will be twice as long

public float GetLastPlayedClipTimeSeconds(Transform owner, bool pitchSpeed)

// Returns the current time (in range 0 to 1) of the AudioClip in the last played AudioSource

// Returns 0 if the InstanceSoundEvent is not playing

// Returns 0 if the SoundEvent or Transform is null

public float GetLastPlayedClipTimeRatio(Transform owner)

// Returns the max length (in seconds) of the SoundEvent (calculated from the longest audioClip)

// Is scaled by the pitch of the SoundEvent and SoundContainer

// Does not take into account random, intensity or parameter pitch

public float GetMaxLength()

// Returns the time (in seconds) since the SoundEvent was played

// Is calculated using the time scale selected in the SoundManager

// Returns 0 if the InstanceSoundEvent is not playing

// Returns 0 if the SoundEvent or Transform is null

public float GetTimePlayed(Transform owner)

Parameters

owner

The owner Transform

pitchSpeed

Determines if it should be scaled by pitch. E.g. -12 semitones will be twice as long

5.6 SoundEvent Get Spectrum Data

// Provides a block of spectrum data from AudioSources

public void GetSpectrumData(Transform owner, ref float[] samples, int channel, FFTWindow window, SpectrumDataFrom spectrumDataFrom)

Parameters

owner

The owner Transform

samples

The array to populate with audio samples. Its length must be a power of 2

channel

The channel to sample from

window

The FFTWindow type to use when sampling

spectrumDataFrom

Where to get the spectrum data from

5.7 SoundEvent Load or Unload Audio Data

// Loads the audio data of any AudioClips assigned to the SoundContainers of the SoundEvent

public void LoadAudioData()

// Unloads the audio data of any AudioClips assigned to the SoundContainers of the SoundEvent

public void UnloadAudioData()

5.8 SoundEvent 2D Play

Useful if you want to play SoundEvents without passing an owner.

// Plays the SoundEvent with the 2D Transform as owner

// Useful to play e.g. UI or other 2D sounds without having to pass a Transform

// To make the sound 2D you still need to disable distance and set spatial blend to 0 in the SoundContainer

public void Play2D()
public void Play2D(SoundTag localSoundTag)
public void Play2D(params SoundParameterInternals[] soundParameterInternals)
public void Play2D(SoundTag localSoundTag, params SoundParameterInternals[] soundParameterInternals)

// Plays the SoundEvent at the position with the 2D Transform as owner (Useful for UnityEvents because it only has one parameter)

public void Play2DAtPosition(Vector3 position)

public void Play2DAtPosition(Transform position)

Parameters

localSoundTag

The SoundTag which will determine the Local SoundTag of the SoundEvent

soundParameterInternals

For example SoundParameterVolumeDecibel is used to modify how the SoundEvent is played

position

The Transform or Vector3 where is should play at (Transform can follow position)

5.9 SoundEvent 2D Stop

// Stops the SoundEvent at the 2D Transform

public void Stop2D(bool allowFadeOut = true)

// Stops all SoundEvents at the 2D Transform

public void StopAll2D(bool allowFadeOut = true)

Parameters

allowFadeOut

If the SoundEvent should be allowed to fade out. Otherwise it is going to be stopped immediately

5.10 SoundEvent 2D Pause and Unpause

// Pauses/unpauses the SoundEvent at the 2D Transform locally

public void Pause2D(bool forcePause = false)

public void Unpause2D()

// Pauses/unpauses all SoundEvents at the 2D Transform locally

public void PauseAll2D(bool forcePause = false)

public void UnpauseAll2D()

Parameters

forcePause

If the SoundEvent should be paused even if it is set to "Ignore Local Pause"

5.11 SoundEvent 2D Get State, Length and Time

// Uses the 2D owner Transform

// If playing it returns SoundEventState.Playing

// If paused either locally or globally it returns SoundEventState.Paused

// If not playing, but it is delayed it returns SoundEventState.Delayed

// If not playing and it is not delayed it returns SoundEventState.NotPlaying

// If the SoundEvent or Transform is null it returns SoundEventState.NotPlaying

public SoundEventState Get2DSoundEventState()

// Uses the 2D owner Transform

// Returns the length (in seconds) of the AudioClip in the last played AudioSource

// Returns 0 if the InstanceSoundEvent is not playing

// Returns 0 if the SoundEvent or Transform is null

// pitchSpeed determines if it should be scaled by pitch. E.g. -12 semitones will be twice as long

public float Get2DLastPlayedClipLength(bool pitchSpeed)

// Uses the 2D owner Transform

// Returns the current time (in seconds) of the AudioClip in the last played AudioSource

// Returns 0 if the InstanceSoundEvent is not playing

// Returns 0 if the SoundEvent or Transform is null

// pitchSpeed determines if it should be scaled by pitch. E.g. -12 semitones will be twice as long

public float Get2DLastPlayedClipTimeSeconds(bool pitchSpeed)

// Uses the 2D owner Transform

// Returns the current time (in range 0 to 1) of the AudioClip in the last played AudioSource

// Returns 0 if the InstanceSoundEvent is not playing

// Returns 0 if the SoundEvent or Transform is null

public float Get2DLastPlayedClipTimeRatio()

// Uses the 2D owner Transform

// Returns the time (in seconds) since the SoundEvent was played

// Is calculated using the time scale selected in the SoundManager

// Returns 0 if the InstanceSoundEvent is not playing

// Returns 0 if the SoundEvent or Transform is null

public float Get2DTimePlayed()

// Returns the owner Transform used by Play2D() etc

public Transform Get2DTransform()

Parameters

pitchSpeed

Determines if it should be scaled by pitch. E.g. -12 semitones will be twice as long

5.12 SoundEvent Music Play

Useful if you want to play music with automatic stopping of the old music when playing a new song.

// Plays the SoundEvent at the SoundManagers music Transform

public void PlayMusic(bool stopAllOtherMusic = true, bool allowFadeOut = true)

public void PlayMusic(bool stopAllOtherMusic = true, bool allowFadeOut = true, params SoundParameterInternals[] soundParameterInternals)

// Plays allowing fade out (Useful for UnityEvents because it only has one parameter)

public void PlayMusicAllowFadeOut(bool stopAllOtherMusic = true)

// Plays without fade out (Useful for UnityEvents because it only has one parameter)

public void PlayMusicImmediate(bool stopAllOtherMusic = true)

Parameters

stopAllOtherMusic

If all other SoundEvents played at the SoundManager music Transform should be stopped

allowFadeOut

If the other stopped SoundEvent should be allowed to fade out. Otherwise they are going to be stopped immediately

soundParameterInternals

For example SoundParameterVolumeDecibel is used to modify how the SoundEvent is played

5.13 SoundEvent Music Stop

// Stops the SoundEvent playing at the Music Transform

public void StopMusic(bool allowFadeOut = true)

// Stops all the SoundEvents playing at the Music music Transform

public void StopAllMusic(bool allowFadeOut = true)

Parameters

allowFadeOut

If the other stopped SoundEvent should be allowed to fade out. Otherwise they are going to be stopped immediately

5.14 SoundEvent Music Pause and Unpause

// Pauses/unpauses the SoundEvent at the Music Transform locally

public void PauseMusic(bool forcePause = false)

public void UnpauseMusic()

// Pauses/unpauses all SoundEvents at the Music Transform locally

public void PauseAllMusic(bool forcePause = false)

public void UnpauseAllMusic()

Parameters

forcePause

If the SoundEvent should be paused even if it is set to "Ignore Local Pause"

5.15 SoundEvent Music Get State, Length and Time

// Uses the Music owner Transform

// If playing it returns SoundEventState.Playing

// If paused either locally or globally it returns SoundEventState.Paused

// If not playing, but it is delayed it returns SoundEventState.Delayed

// If not playing and it is not delayed it returns SoundEventState.NotPlaying

// If the SoundEvent or Transform is null it returns SoundEventState.NotPlaying

public SoundEventState GetMusicSoundEventState()

// Uses the Music owner Transform

// Returns the length (in seconds) of the AudioClip in the last played AudioSource

// Returns 0 if the InstanceSoundEvent is not playing

// Returns 0 if the SoundEvent or Transform is null

// pitchSpeed determines if it should be scaled by pitch. E.g. -12 semitones will be twice as long

public float GetMusicLastPlayedClipLength(bool pitchSpeed)

// Uses the Music owner Transform

// Returns the current time (in seconds) of the AudioClip in the last played AudioSource

// Returns 0 if the InstanceSoundEvent is not playing

// Returns 0 if the SoundEvent or Transform is null

// pitchSpeed determines if it should be scaled by pitch. E.g. -12 semitones will be twice as long

public float GetMusicLastPlayedClipTimeSeconds(bool pitchSpeed)

// Uses the Music owner Transform

// Returns the current time (in range 0 to 1) of the AudioClip in the last played AudioSource

// Returns 0 if the InstanceSoundEvent is not playing

// Returns 0 if the SoundEvent or Transform is null

public float GetMusicLastPlayedClipTimeRatio()

// Uses the Music owner Transform

// Returns the time (in seconds) since the SoundEvent was played

// Is calculated using the time scale selected in the SoundManager

// Returns 0 if the InstanceSoundEvent is not playing

// Returns 0 if the SoundEvent or Transform is null

public float GetMusicTimePlayed()

// Returns the owner Transform used by PlayMusic() etc

public Transform GetMusicTransform()

Parameters

pitchSpeed

Determines if it should be scaled by pitch. E.g. -12 semitones will be twice as long

6 Modifiers

Modifiers are used to control how SoundEvents are played (e.g. volume, polyphony, fade in length etc).

They are available on the SoundEvent, SoundTrigger, SoundPicker and SoundMix objects.

They have similar functionality as the SoundParameters, but with visual editing.

Modifiers are only updated once when starting the SoundEvent, not continuously.

Some modifiers use priorities to determine what a final modifier value should be.

The modifier with the highest priority will determine the value.

1st: SoundParameter

2nd: SoundMix

3rd: SoundTrigger/SoundPicker

4th: SoundTag

5th: SoundEvent

Volume dB

Volume offset in decibel.

If you want to change the volume of a sound which is already playing, use the Timeline or SoundContainer volume.

Pitch st

Pitch offset in semitones.

Delay

Increase the delay in seconds.

Start Position

Sets the start position, 0 is the start, 1 is the end.

The highest priority added modifier will determine the value.

Reverse

If enabled the AudioClip will be played backwards.

Make sure to set the start position to the end.

Reverse is only supported for AudioClips which are stored in an uncompressed format or will be decompressed at load time.

The highest priority added modifier will determine the value.

Distance Scale

Distance scale multiplier (how far it will be heard).

It is multiplied by the Distance Scale of the SoundManager.

Reverb Zone Mix dB

Reverb Zone Mix volume offset in decibel.

Fade In Length

The length of the fade in.

Is calculated using the time scale selected in the SoundManager.

The highest priority added modifier will determine the value.

Fade In Shape

Shape of the fade in

Negative is exponential, 0 is linear, positive is logarithmic.

The highest priority added modifier will determine the value.

Fade Out Length

The length of the fade out.

Is calculated using the time scale selected in the SoundManager.

The highest priority added modifier will determine the value.

Fade Out Shape

Shape of the fade out

Negative is exponential, 0 is linear, positive is logarithmic.

The highest priority added modifier will determine the value.

Increase 2D

Makes the SoundEvent more 2D (less spatialized).

Useful for first person sounds.

Stereo Pan

Stereo pan offset

-1 is left, 0 is centered, +1 is right.

Intensity

Multiplier of any used SoundParameterIntensity parameter.

Distortion Increase

Increases the distortion.

Distortion needs to be enabled on the SoundContainer for this to have any effect.

Polyphony

How many instances of the SoundEvent that can exist at the same transform.

The highest priority added modifier will determine the value.

Follow Position

If the SoundEvent should follow the given Transform position.

The highest priority added modifier will determine the value.

Bypass Reverb Zones

If enabled all reverb zones will be bypassed.

The highest priority added modifier will determine the value.

Bypass Voice Effects

If enabled all voice effects (lowpass/highpass/distortion) will be bypassed.

The highest priority added modifier will determine the value.

Bypass Listener Effects

If enabled all listener effects will be bypassed.

The highest priority added modifier will determine the value.

7 SoundParameter

SoundParameters are used to control how SoundEvents are played (e.g. volume, polyphony, fade in length etc).

They can be passed when playing a SoundEvent and set to update either once or continuously.

They have similar functionality as the Modifiers, but with scripting capabilities.

Example code:

using UnityEngine;
using Sonity;

public class ExampleSoundParameter : MonoBehaviour {

   
public SoundEvent soundEvent;

    SoundParameterVolumeDecibel volumeParameter = new SoundParameterVolumeDecibel(0f, UpdateMode.Once);


   
void Start() {
       
// Sets the volume parameter to a random value between -12 dB and 0 dB
       volumeParameter.volumeDecibel =
Random.Range(-12f, 0f);

        // Plays the SoundEvent with the sound parameter

        soundEvent.Play(transform, volumeParameter);
   }
}

Update Modes

The UpdateMode enum determines if the SoundEvent will take the parameter into consideration only once at start or if it will be updated continuously.

// The SoundParameter will update only once

UpdateMode.Once

// The SoundParameter will update continuously

UpdateMode.Continuous

Parameter Types

The parameter type determines which parameter of the SoundEvent will be controlled.

See Modifiers for more detailed info on the individual parameters.

// Volume offset in decibel. Range -Infinity to 0

public class SoundParameterVolumeDecibel(float volumeDecibel = 0f, UpdateMode updateMode = UpdateMode.Once)

// Volume ratio multiplier. Range 0f to 1f

public class SoundParameterVolumeRatio(float volumeRatio = 1f, UpdateMode updateMode = UpdateMode.Once)

// Pitch offset in semitones

public class SoundParameterPitchSemitone(float pitchSemitone = 0f, UpdateMode updateMode = UpdateMode.Once)

// Pitch offset ratio multiplier. Range 0 to Infinity

public class SoundParameterPitchRatio(float pitchRatio = 1f, UpdateMode updateMode = UpdateMode.Once)

// Delay increase. Range 0 to Infinity

public class SoundParameterDelay(float delay = 0f)

// Makes the sound more 2D (less spatialized). Range 0 to 1

public class SoundParameterIncrease2D(float increase2D = 0f, UpdateMode updateMode = UpdateMode.Once)

// Controls the intensity of the SoundContainer

// Go to the SoundContainer to change how intensity will affect the sound

public class SoundParameterIntensity(float intensity = 1f, UpdateMode updateMode = UpdateMode.Once)

// Reverb zone mix offset in decibel. Range -Infinity to 0

public class SoundParameterReverbZoneMixDecibel(float reverbZoneMixDecibel = 0f, UpdateMode updateMode = UpdateMode.Once)

// Reverb zone mix ratio multiplier. Range 0 to 1

public class SoundParameterReverbZoneMixRatio(float reverbZoneMixRatio = 1f, UpdateMode updateMode = UpdateMode.Once)

// Reverb zone mix ratio multiplier. Range 0 to 1

public class SoundParameterReverbZoneMixRatio(float reverbZoneMixRatio = 1f, UpdateMode updateMode = UpdateMode.Once)

// Start position. Range 0 to 1

public class SoundParameterStartPosition(float startPosition = 0f)

// If the sound should be played backwards. If enabled, set the start position to the end.

// Reverse is only supported for AudioClips which are stored in an uncompressed format or will be decompressed at load time.

public class SoundParameterReverse(bool reverse = false)

// The polyphony of the SoundEvent. Range 1 to int.MaxValue

public class SoundParameterPolyphony(int polyphony = 1)

// Distance scale multiplier. Range 0 to Infinity

public class SoundParameterDistanceScale(float distanceScale = 1f)

// Distortion increase. Range 0 to 1

public class SoundParameterDistortionIncrease(float distortionIncrease = 1f, UpdateMode updateMode = UpdateMode.Once)

// Fade in length. Range 0 to Infinity

public class SoundParameterFadeInLength(float fadeInLength = 0f, UpdateMode updateMode = UpdateMode.Once)

// Fade in shape. Range -16 to 16 (negative is exponential, 0 is linear, positive is logarithmic)

public class SoundParameterFadeInShape(float fadeInShape = 2f, UpdateMode updateMode = UpdateMode.Once)

// Fade out length. Range 0 to Infinity

public class SoundParameterFadeOutLength(float fadeOutLength = 0f, UpdateMode updateMode = UpdateMode.Once)

// Fade out shape. Range -16 to 16 (negative is exponential, 0 is linear, positive is logarithmic)

public class SoundParameterFadeOutShape(float fadeOutShape = -2f, UpdateMode updateMode = UpdateMode.Once)

// If the SoundEvent should follow the Transform position

public class SoundParameterFollowPosition(bool followPosition = true, UpdateMode updateMode = UpdateMode.Once)

// If reverb zones should be bypassed

public class SoundParameterBypassReverbZones(bool bypassReverbZones = false, UpdateMode updateMode = UpdateMode.Once)

// If voice effects (distortion/lowpass/highpass) should be bypassed

public class SoundParameterBypassVoiceEffects(bool bypassEffects = false, UpdateMode updateMode = UpdateMode.Once)

// If listener effects should be bypassed

public class SoundParameterBypassListenerEffects(bool bypassListenerEffects = false, UpdateMode updateMode = UpdateMode.Once)

8 SoundParameterIntensity

SoundParameterIntensity is used to pass an intensity value to a SoundContainer when playing a SoundEvent.

This value can be anything you want to affect your sound, e.g. velocity, the size of an explosion, the speed of a car, etc.

The SoundContainer can scale and use the intensity parameter to control intensity options e.g. volume, pitch, distortion etc.

Tip: You can record and debug the intensity at the Intensity in the SoundContainer.

Example code:

using UnityEngine;
using Sonity;

public class ExampleIntensityParameter: MonoBehaviour {

   
public SoundEvent soundEvent;

    SoundParameterIntensity intensityParameter = new SoundParameterIntensity(1f, UpdateMode.Once);


   
void OnCollisionEnter(Collision collision) {
       
// Sets the intensity parameter to the velocity of the collision
       intensityParameter.intensity = collision.relativeVelocity.magnitude;

        // Plays the SoundEvent with the intensity parameter

        soundEvent.Play(transform, intensityParameter);
   }
}

Refer to the following examples:

Car motor example

The speed of the car is passed as an continuous intensity parameter which controls the intensity pitch and volume of the SoundContainer.

Physics impact example

The velocity of the impact is passed once as an intensity parameter which controls the intensity volume and intensity lowpass filter of the SoundContainer.

(Check out the SoundPhysics component for easily playing physics sounds)

For volume intensity you can crossfade between any number of layers (eg. hard/medium/soft) easily and accurately.

The default settings of the lowpass filter intensity settings make the sound more filtered the lower the intensity value is.

E.g. 0 intensity is maximum filter effect and 1 intensity is unfiltered.

9 SoundTrigger Component

SoundTrigger is a component used for easily playing/stopping SoundEvents on callbacks built into Unity like Enable, Disable, OnCollisionEnter etc.

They contain SoundEvents with modifiers and triggers which decide when it should play or stop.

SoundTriggers also have a radius handle, which is visually editable in the scene viewport for easy adjustment of how far SoundEvents should be heard.

All SoundTrigger components are multi-object editable.

Distance Radius

Distance of the SoundEvent (how far it should be heard).

Modifiers

Modifiers are used to control how SoundEvents are played (e.g. volume, polyphony, fade in length etc).

See Modifiers for more info.

Triggers

Using the triggers you can select when an action happens.

On Trigger and On Collision - Tag

If enabled, the SoundEvent will only play if the triggering object has a tag matching the selected tags.

On Collision - Velocity to Intensity

If enabled, the velocity magnitude will be passed as an intensity parameter.

Actions

For each trigger you can select what it should do to the SoundEvent.

9.1 SoundTrigger Custom Override

You can override the functionality and editor of the SoundTrigger and extend it with custom functionality.

Example result:

SoundTriggerCustom.cs

using Sonity;

public class SoundTriggerCustom : SoundTrigger {


   
// Add custom code or functionality here

    public bool customBoolShouldPlay = true;

    // Example override, you can override e.g. OnTriggerEnter etc.
   
protected override void OnEnable() {
       
if (customBoolShouldPlay) {

            base.OnEnable();

        }
   }
}

SoundTriggerCustomEditor.cs

using Sonity.Internal;
using UnityEditor;

#if UNITY_EDITOR

[CustomEditor(typeof(SoundTriggerCustom))]

[CanEditMultipleObjects]
public class SoundTriggerCustomEditor : SoundTriggerEditor {

   
private SoundTriggerCustom soundTriggerCustom;

   
protected override void OnEnable() {

        base.OnEnable();
       
// Get the target property
       soundTriggerCustom = (
SoundTriggerCustom)target;
   }

   
public override void OnInspectorGUI() {

       
       
// Draw the new property for the custom editor
       
BeginChange();

        SerializedProperty customBoolShouldPlay = serializedObject.FindProperty(nameof(SoundTriggerCustom.customBoolShouldPlay));

        EditorGUILayout.PropertyField(customBoolShouldPlay);

        EndChange();

       

        // Draw the original GUI
       
base.OnInspectorGUI();
   }
}

#endif

10 SoundTrigger Functions

10.1 SoundTrigger Play

// Plays the SoundEvent at the position of the owner Transform

public void Play()
public void Play(SoundTag localSoundTag)
public void Play(params SoundParameterInternals[] soundParameterInternals)
public void Play(SoundTag localSoundTag, params SoundParameterInternals[] soundParameterInternals)

Parameters

localSoundTag

The SoundTag which will determine the Local SoundTag of the SoundEvent

soundParameterInternals

For example SoundParameterVolumeDecibel is used to modify how the SoundEvent is played

10.2 SoundTrigger PlayAtPosition

// Plays the SoundEvent at the Vector3 position with another Transform as the owner

public void PlayAtPosition(Vector3 position)
public void PlayAtPosition(Vector3 position, SoundTag localSoundTag)
public void PlayAtPosition(Vector3 position, params SoundParameterInternals[] soundParameterInternals)
public void PlayAtPosition(Vector3 position, SoundTag localSoundTag, params SoundParameterInternals[] soundParameterInternals)

// Plays the SoundEvent at the Transform position with another Transform as the owner

public void PlayAtPosition(Transform position)
public void PlayAtPosition(Transform position, SoundTag localSoundTag)
public void PlayAtPosition(Transform position, params SoundParameterInternals[] soundParameterInternals)
public void PlayAtPosition(Transform position, SoundTag localSoundTag, params SoundParameterInternals[] soundParameterInternals)

Parameters

owner

The owner Transform

position

The Transform or Vector3 where is should play at (Transform can follow position)

localSoundTag

The SoundTag which will determine the Local SoundTag of the SoundEvent

soundParameterInternals

For example SoundParameterVolumeDecibel is used to modify how the SoundEvent is played

10.3 SoundTrigger Stop

Tip: You really only need to use stop for looping or longer oneshot sounds (or the SoundContainer “Stop if Transform is Null” setting).

Use the polyphony setting in the SoundEvent to manage the number of instances playing.

// Stops the SoundEvent at the owner Transform

public void Stop(bool allowFadeOut = true)

// Stops the SoundEvent at the position Transform

public void StopAtPosition(Transform position, bool allowFadeOut = true)

Parameters

position

The position Transform

allowFadeOut

If the SoundEvent should be allowed to fade out. Otherwise it is going to be stopped immediately

10.4 SoundTrigger Pause and Unpause

// Pauses/unpauses the SoundEvent with the owner Transform locally

public void Pause(bool forcePause = false)

public void Unpause()

// Pauses/unpauses the SoundEvent everywhere locally

public void PauseEverywhere(bool forcePause = false)

public void UnpauseEverywhere()

Parameters

forcePause

If the SoundEvent should be paused even if it is set to "Ignore Local Pause"

10.5 SoundTrigger Get State

// If playing it returns SoundEventState.Playing

// If paused either locally or globally it returns SoundEventState.Paused

// If not playing, but it is delayed it returns SoundEventState.Delayed

// If not playing and it is not delayed it returns SoundEventState.NotPlaying

// If the SoundEvent or Transform is null it returns SoundEventState.NotPlaying

public SoundEventState GetSoundEventState(Transform owner)

10.6 SoundTrigger Load or Unload Audio Data

// Loads the audio data of any AudioClips assigned to the SoundContainers of the SoundEvent

public void LoadAudioData()

// Unloads the audio data of any AudioClips assigned to the SoundContainers of the SoundEvent

public void UnloadAudioData()

11 SoundPhysics

(SoundPhysics is remade in Sonity 1.0.5 with expanded functionality)

SoundPhysics is a component used for easily playing SoundEvents on physics interactions.

SoundPhysics is split up into 3D/2D versions with and without friction because of performance reasons.

If friction sounds aren’t needed and performance is a priority then use the SoundPhysics with no friction.

A Rigidbody/Rigidbody2D is required on this object.

One or several Collider/Collider2D should be placed on this object or its children.

Use intensity record in the SoundEvent for easy scaling of the velocity into a 0 to 1 range.

All SoundPhysics components are multi-object editable.

Impact

Is triggered when the object starts touching a collider.

OnCollision uses velocity from Collision.relativeVelocity.magnitude and the position of the Collision.contacts with the highest impulse.magnitude.

OnTrigger uses velocity from Rigidbody.velocity.magnitude.

Friction

Is triggered when the object is continuously touching a collider.

Uses velocity from Rigidbody.velocity.magnitude.

Exit

Is triggered when the object stops touching a collider.

Uses velocity from Rigidbody.velocity.magnitude.

SoundEvent

The SoundEvents which are to be played.

Play On

Selects if the SoundEvents should be played when a OnCollision and/or OnTrigger event occurs.

OnTrigger is when you have a collider which is set to “Is Trigger”.

Conditions

If enabled then any SoundPhysicsCondition added will be used to decide if the physics interaction should play a SoundEvent or not.

SoundPhysicsConditions can also be used for playing different sounds with a single SoundEvent by assigning SoundTags in the SoundPhysicsConditions.

SoundTags

If enabled then any SoundTags added will be sent when triggering the SoundEvent.

If a SoundTag is not null it will override any SoundTags which might be sent through the SoundPhysicsConditions.

SoundTags can be used for triggering different sounds with a single SoundEvent.

Intensity

All SoundEvents played with SoundPhysics are sent a velocity through the SoundParameterIntensity.

This can be used to control the sound e.g. making it quieter when the velocity is lower.

Read more at SoundParameterIntensity.

For how to debug playing sounds in the scene/game view check out SoundManager Debug SoundEvents Live.

Example of how to record and debug SoundParameterIntensity.

This is helpful for scaling the incoming velocity values to a 0 to 1 range.

11.1 SoundPhysicsCondition

SoundPhysicsCondition objects are used in the SoundPhysics component to decide if a physics interaction should play a SoundEvent or not.

They make it easy to manage a large amount of physics objects and linking conditions together with the child nesting feature.

You can also use them for playing different sounds with a single SoundEvent by using SoundTags.

All SoundPhysicsCondition objects are multi-object editable.

Children

You can nest SoundPhysicsConditions so you don't have to update all your SoundPhysics components when adding a new SoundPhysicsCondition.

The children of the parent SoundPhysicsCondition are evaluated after the parent.

Parent

The parent SoundPhysicsCondition is evaluated before the children.

SoundTag

By utilizing the SoundTags you can play different sounds with a single SoundEvent (see the example physics assets on how you can set that up).

If no SoundTag is assigned it won't affect the output SoundTag, so if a child has an assigned SoundTag and the parent doesn't, the child one will be used.

They are useful to split into different child SoundPhysicsConditions with different SoundTags.

Play On

Selects if it should be played when a OnCollision and/or OnTrigger event occurs.

OnTrigger is when you have a collider which is set to “Is Trigger”.

Play Disregarding Conditions

If enabled the SoundPhysicsCondition will play regardless of its own conditions.

Useful to combine with child SoundPhysicsConditions with different SoundTags.

Abort All On No Match

If enabled and the assigned condition is not matched it will abort playing and disregard all other conditions.

If not enabled and the assigned condition is not matched another condition which is met can play the sound.

Abort All On Match

If enabled and the assigned condition is matched it will abort playing and disregard all other conditions.

If not enabled and the assigned condition is matched another condition which is met can play the sound.

Tag

Checks if the Tag of the colliding GameObject matches any of the specified Tags.

Layer

Checks if the Layer of the colliding GameObject matches any of the specified Layers.

Terrain Name

Checks if the name of the most dominant Terrain Layer of the colliding Terrain contains any of the specified strings (it is not case sensitive).

E.g. you have multiple Terrain Layers with different grass textures, if the names of the Terrain Layers contain the string it will play the sound.

Terrain conditions are only evaluated if the colliding object has a Terrain component.

The center point of the SoundPhysics object is used to calculate the dominant Terrain Layer because it is more stable than the contacts.

Terrain Index

Checks if the index of the most dominant Terrain Layer of the colliding Terrain is any of the specified indexes.

Terrain conditions are only evaluated if the colliding object has a Terrain component.

The center point of the SoundPhysics object is used to calculate the dominant Terrain Layer because it is more stable than the contacts.

Component

Checks if the Components of the colliding GameObject match any of the specified Components.

The names are case sensitive.

12 SoundPicker

SoundPicker is a serializable class for easily selecting multiple SoundEvents and modifiers.

Add a serialized or public SoundPicker to a C# script and edit it in the inspector.

SoundPickers are multi-object editable.

SoundEvent

The SoundEvent to play.

Modifiers

Modifiers are used to control how SoundEvents are played (e.g. volume, polyphony, fade in length etc).

See Modifiers for more info.

Example code:

using UnityEngine;
using Sonity;

public class ExampleSoundPicker : MonoBehaviour {

   
public SoundPicker soundPicker;

   
void Start() {
       
// Plays the SoundPicker at the position of the transform
       soundPicker.
Play(transform);
   }
}

13 SoundPicker Functions

13.1 SoundPicker Play

// Plays the SoundEvent at the position of the owner Transform

public void Play(Transform owner)
public void Play(Transform owner, SoundTag localSoundTag)
public void Play(Transform owner, params SoundParameterInternals[] soundParameterInternals)
public void Play(Transform owner, SoundTag localSoundTag, params SoundParameterInternals[] soundParameterInternals)

Parameters

owner

The owner Transform

localSoundTag

The SoundTag which will determine the Local SoundTag of the SoundEvent

soundParameterInternals

For example SoundParameterVolumeDecibel is used to modify how the SoundEvent is played

13.2 SoundPicker PlayAtPosition

// Plays the SoundEvent at the Vector3 position with another Transform as the owner

public void PlayAtPosition(Transform owner, Vector3 position)
public void PlayAtPosition(Transform owner, Vector3 position, SoundTag localSoundTag)
public void PlayAtPosition(Transform owner, Vector3 position, params SoundParameterInternals[] soundParameterInternals)
public void PlayAtPosition(Transform owner, Vector3 position, SoundTag localSoundTag, params SoundParameterInternals[] soundParameterInternals)

// Plays the SoundEvent at the Transform position with another Transform as the owner

public void PlayAtPosition(Transform owner, Transform position)
public void PlayAtPosition(Transform owner, Transform position, SoundTag localSoundTag)
public void PlayAtPosition(Transform owner, Transform position, params SoundParameterInternals[] soundParameterInternals)
public void PlayAtPosition(Transform owner, Transform position, SoundTag localSoundTag, params SoundParameterInternals[] soundParameterInternals)

Parameters

owner

The owner Transform

position

The Transform or Vector3 where is should play at (Transform can follow position)

localSoundTag

The SoundTag which will determine the Local SoundTag of the SoundEvent

soundParameterInternals

For example SoundParameterVolumeDecibel is used to modify how the SoundEvent is played

13.3 SoundPicker Stop

Tip: You really only need to use stop for looping or longer oneshot sounds (or the SoundContainer “Stop if Transform is Null” setting).

Use the polyphony setting in the SoundEvent to manage the number of instances playing.

// Stops the SoundEvent at the owner Transform

public void Stop(Transform owner, bool allowFadeOut = true)

// Stops the SoundEvent at the position Transform

public void StopAtPosition(Transform position, bool allowFadeOut = true)

Parameters

owner

The owner Transform

position

The position Transform

allowFadeOut

If the SoundEvent should be allowed to fade out. Otherwise it is going to be stopped immediately

13.4 SoundPicker Pause and Unpause

// Pauses/unpauses the SoundEvent with the owner Transform locally

public void Pause(Transform owner, bool forcePause = false)

public void Unpause(Transform owner)

// Pauses/unpauses the SoundEvent everywhere locally

public void PauseEverywhere(bool forcePause = false)

public void UnpauseEverywhere()

Parameters

owner

The owner Transform

forcePause

If the SoundEvent should be paused even if it is set to "Ignore Local Pause"

13.5 SoundPicker Get State, Length and Time

// If playing it returns SoundEventState.Playing

// If paused either locally or globally it returns SoundEventState.Paused

// If not playing, but it is delayed it returns SoundEventState.Delayed

// If not playing and it is not delayed it returns SoundEventState.NotPlaying

// If the SoundEvent or Transform is null it returns SoundEventState.NotPlaying

public SoundEventState GetSoundEventState(Transform owner)

Parameters

owner

The owner Transform

13.6 SoundPicker Load or Unload Audio Data

// Loads the audio data of any AudioClips assigned to the SoundContainers of the SoundEvent

public void LoadAudioData()

// Unloads the audio data of any AudioClips assigned to the SoundContainers of the SoundEvent

public void UnloadAudioData()

14 SoundMix

SoundMix objects are used for grouped control of e.g. volume for multiple SoundEvents at the same time.

They contain a parent SoundMix and modifiers for the SoundEvents.

All SoundMix objects are multi-object editable.

They can be used instead of AudioMixerGroups if you need increased performance.

Example use; set up a “Master_MIX” and a “SFX_MIX” where the Master_MIX is a parent of the SFX_MIX.

Performance tips:

If you have issues with audio performance you might want to make sure you’re not using an unnecessary amount of AudioMixerGroups.

Because changing AudioMixerGroup for a Voice uses performance (when playing a new Voice Sonity tries to find an unused Voice which uses the same AudioMixerGroup).

Use AudioMixerGroups when you want effects per group or e.g. ducking or for larger groups of sounds, but maybe not a have a unique one for each sound.

If you need to increase performance, look at SoundMix assets for controlling volume hierarchically.

Modifiers

Modifiers are used to control how SoundEvents are played (e.g. volume, polyphony, fade in length etc).

See Modifiers for more info.

15 SoundPolyGroup

SoundPolyGroup objects are used to create a polyphony limit shared by multiple different SoundEvents.

The priority for voice allocation is calculated by multiplying the priority set in the SoundEvent by the volume of the instance.

A perfect use case would be to have a SoundPolyGroup for all bullet impacts of all the different materials so that when combined, they don’t use too many voices.

If you want simple individual polyphony control, use the polyphony modifier on the SoundEvent.

All SoundPolyGroup objects are multi-object editable.

Polyphony Limit

The maximum number of SoundEvents which can be played at the same time in this SoundPolyGroup.

Used in a SoundEvent:

16 SoundTag

SoundTag objects are passed to modify how a SoundEvent should be played.

You can either pass them when playing a SoundEvent for setting the local SoundTag.

Or you can set the global SoundTag in the SoundManager .

This is useful for e.g; weapon reverb zones.

You can set the SoundTag corresponding to the acoustic space which the listener is in.

And when you play the SoundEvent, your gun reflection layers can correspond to the acoustic space.

Used in a SoundEvent:

17 SoundPreset

Use SoundPreset to apply settings to SoundContainers and SoundEvents automatically by matching the names of your assets.

Its matched and applied when you Create Assets From Selection or manually from the SoundContainer Presets and the SoundEvent Presets toolbars.

Example use: Name UI sounds to “UI_” and use Is Prefix “UI_” to automatically assign settings like disabling distance and setting Spatial Blend to 0.

The settings are applied ordering from the one highest up and going downwards and can match an asset multiple times overwriting previous values.

You can have multiple SoundPreset objects.

Example_SoundPreset

If you want a starting point for your SoundPreset, look at the Example_SoundPreset. 

Note: The SoundContainers and SoundEvents have volume -12dB so you can increase the volume later.

You can compensate by increasing the volume in the AudioMixer.

All the SoundEvents are also assigned to a AudioMixerGroup in the Example_AudioMixerWithLimiter.

Example Templates

Template Default (Matches to all to catch any stray sounds without prefix)

Default settings

Outputs to SFX

Template AMB (2D Ambience)

Distance disabled

Spatial Blend 0

Template MUS (Music)

Distance disabled

Spatial Blend 0

Never Steal Voice

Never Steal Voice Effects

Priority 1

Template SFX (Sound Effects)

Default settings

Template UI (User Interface)

Distance disabled

Spatial Blend 0

Template VO (Voice/Dialogue)

Random Pitch disabled

Settings

Disable All

If disabled no settings from the SoundPreset will be applied automatically and not available in the preset menus.

Preset

Disable

If disabled this specific preset won’t be available.

Automatic Loop

If enabled and the SoundContainer name contains “loop” then it will automatically enable “Loop”, “Follow Position”, “Stop if Transform is Null” and “Random Start Position”.

This will be applied after all the other settings are copied.

Is not applied if you manually select a preset from the SoundContainer Presets dropdown.

From SoundContainer

The SoundContainer you want to copy the settings from.

Copies everything except:

- AudioClips

From SoundEvent

The SoundEvent you want to copy the settings from.

Copies everything except:

- SoundContainers

- Timeline Settings

- Intensity Scale Add/Multiplier

- TriggerOn SoundEvents

- SoundTag SoundEvents

Match

Auto Match

If enabled then automatic matching will be used when you Create Assets From Selection and in the SoundContainer Presets and the SoundEvent Presets “Auto Match”.

Disable if you just want presets to apply manually to your assets.

Auto matching is not case sensitive.

Apply On All

If enabled the settings assigned will be applied to all assets on asset creation and “Auto Match”.

Useful to combine with other settings with conditions added later in the chain to assign settings to assets which doesn’t match the names.

Is Prefix

If the prefix of an asset matches the strings, the settings will be applied.

Example prefixes: “AMB”, “MUS”, “SFX”, “UI”, “VO”.

Is Not Prefix

If the prefix of an asset doesn’t match the strings, the settings will be applied.

Contains

If the name of an asset contains the strings, the settings will be applied.

Not Contains

If the name of an asset doesn’t contain the strings, the settings will be applied.

18 SoundDataGroup

SoundDataGroup objects are used to easily load and unload the audio data of the SoundEvents.

All SoundDataGroup objects are multi-object editable.

Child SoundDataGroups

Nesting SoundDataGroups makes it easy to load/unload all audio data or just parts of it.

SoundEvents

The SoundEvent whoms audio data will be loaded or unloaded

Drop SoundEvents/Folders Here

Here you can drag and drop SoundEvents or folders with SoundEvents in them.

Functions Load/Unload

// Loads the audio data for the AudioClips of the assigned SoundEvents.

public void LoadAudioData(bool includeChildren)

// Unloads the audio data for the AudioClips of the assigned SoundEvents.

public void UnloadAudioData(bool includeChildren)

Parameters

includeChildren

If to load/unload all the audio data of all the child SoundDataGroups also.

19 SoundManager Component

The SoundManager is the master object which is used to play sounds and manage global settings.

An instance of this object is required in the scene in order to play SoundEvents.

You can add the pre-made prefab called “SoundManager” found in “Assets\Plugins\Sonity\Prefabs” to the scene.

Or you can add the “Sonity - Sound Manager” component to an empty GameObject in the scene, it works just as well.

Tip: If you need to play SoundEvents on Awake() when starting your game you need to edit the Script Execution Order.

Go to "Project Settings..." -> "Script Execution Order" and add "Sonity.SoundManager".

Then set it to a negative value (like -50) so it loads before the code which you want to use Awake() to play sounds when starting your game.

19.1 SoundManager Settings

Disable Playing Sounds

Disables all the Play functionality.

Useful if you've for example implemented temp sounds and don't want everyone else to hear them.

Global Pause

Pauses or unpauses all sound using AudioListener.pause.

Except the SoundEvents which are set to "Ignore Global Pause".

Note that because AudioListener.pause is used, all other non-Sonity AudioSources will also be paused.

This can be remedied with using AudioSource.ignoreListenerPause.

Can be set with SetGlobalPause() and SetGlobalUnpause() in the SoundManager."

Global Volume

Sets the global volume using AudioListener.volume.

Note that because AudioListener.volume is used, all other non-Sonity AudioSources will also be affected.

This can be remedied with using AudioSource.ignoreListenerVolume.

Can be set with SetGlobalVolumeDecibel() and SetGlobalVolumeRatio() in the SoundManager."

Sound Time Scale

Change the Time Scale used for sound related calculations ingame.

When the game is not playing in the editor, only Time.realtimeSinceStartup can be used (for preview, etc).

The Time Scale is used to calculate:

Global SoundTag

The selected Global SoundTag.

SoundEvents using global SoundTag are affected by this.

Override Listener Distance

If enabled an AudioListenerDistance component is required in the scene.

The position of the AudioListenerDistance component will determine all distance based calculations (like volume falloff).

While the AudioListener position will be used for spatialization and Angle to Stereo Pan calculations.

Example of usage in a 3rd person or top down game:

Enable "Override Listener Distance" in the SoundManager.

Put the AudioListener on the main camera and the AudioListenerDistance on the player character.

Try changing the Amount slider to find a nice balance between the different positions.

Amount %

How much weight the AudioListenerDistance position has over the AudioListener position.

The position is linearly interpolated between the two of them.

100% is at the AudioListenerDistance component position.

50% is halfway between them.

0% is at the AudioListener position.

Distance Scale

Global range scale multiplier for all the sounds in Sonity.

Distance is calculated by Unity units of distance.

E.g. if Distance Scale is set to 100, a SoundEvent with the distance multiplier of 1 will be heard up to 100 Unity units away.

Enable Speed of Sound

Speed of sound is a delay based on the distance between the Audio Listener and a SoundEvent.

Speed of Sound Scale

Global speed of sound delay scale multiplier.

1 equals 430 Unity units per second.

Is calculated using the time scale selected in the SoundManager.

Use DontDestroyOnLoad()

Calls DontDestroyOnLoad() at Start for Sonity objects.

Which makes them persistent when switching scenes.

For this to work the parent is set to null, which can move the objects.

Debug Warnings

Makes Sonity output Debug Warnings if anything is wrong.

Debug in Play Mode

Makes Sonity output Debug Warnings if anything is wrong in Play Mode.

GUI Warnings

Makes Sonity show GUI Warnings if anything is wrong in the editor.

19.2 SoundManager Performance

Voice Limit

Maximum number of Voices.

If the limit is reached it will steal the Voice with the lowest priority.

If you need extra performance, you could try lowering the real and virtual voices to a lower number.

Voice Limit cannot be lower than Voice Preload.

Max Real Voices:

The maximum number of real (heard) AudioSources that can be played at the same time.

"Real Voices" should be the same as the "Voice Limit", or more if you play other sounds outside of Sonity.

Max Virtual Voices:

The maximum number of virtual (not heard) AudioSources that can be played at the same time.

This should always be more than the number of real voices.

You can change these values manually in:

"Edit" > "Project Settings" > "Audio"

Apply to Project Audio Settings

Applies the Voice Limit to the Project Audio Settings.

Sets "Real Voices" to the "Voice Limit".

You can change these values manually in:

"Edit" > "Project Settings" > "Audio"

Voice Preload

How many Voices to preload on Awake().

Voice Limit cannot be lower than Voice Preload.

Voice Disable Time

How long in seconds to wait before disabling a Voice when they've stopped playing.

Retriggering a voice which is not disabled is more performant than retriggering a voice which is disabled.

But having a lot of voices enabled which aren't used is also not good for performance, so don't set this value too high.

Is calculated using the time scale selected in the SoundManager.

Voice Effect Limit

Maximum number of Voice Effects which can be used at the same time.

A Voice with any combination of waveshaper/lowpass/highpass counts as one Voice Effect.

If the values of a Voice Effect doesn't have any effect it is disabled automatically (e.g. distortion amount is 0).

If the Voice Effect limit is reached, the Voice Effects are prioritized by the Voices with the highest volume * priority.

Watch out for high load on the audio thread if set too high.

Try setting the buffer size to "Best Performance" in "Edit" > "Project Settings" > "Audio" if you want to run more Voice Effects.

19.3 SoundManager Debug SoundEvents Live

Debug SoundEvents live draws the names of all currently playing SoundEvent in the scene and/or game view.

Useful for debugging when you want to see what is playing and where.

In Scene View

Draws debug names in the Unity scene view.

Doesn't work in Unity versions older than 2019.1.

Example:

In Game View

Draws debug names in the Unity game view.

Only applied in the Unity editor.

Example:

Font Size

The font size of the text.

Volume to Alpha

How much of the volume of the SoundEvent will be applied to the transparency of the text.

E.g lower volumes will be more transparent.

Lifetime to Alpha

How much the lifetime of the SoundEvent will affect the transparency of the text.

Lifetime Fade Length

How long the fade should be.

Is calculated using the time scale selected in the SoundManager.

Lifetime Start Color

The color the text should have when it starts playing.

Lifetime Fade Color

Which color the text should fade to over the lifetime.

Outline Color

The color of the text outline.

19.4 SoundManager Global Statistics

SoundEvents

Statistics of SoundEvents.

Created

The number of instantiated SoundEvents.

Active

The number of active SoundEvents.

Disabled

The number of unused and disabled SoundEvents.

Voices

Statistics of Voices.

Played

The number of played Voices since start.

Stolen

The number of stolen Voices since start.

Max Simultaneous

The maximum number of simultaneously playing Voices since start.

Created

The number of Voices in the pool.

Active

The number of Voices playing audio.

Inactive

The number of inactive Voices in the pool.

Paused

The number of paused Voices in the pool.

Stopped

The number of stopped Voices in the pool.

Voice Effects

Statistics of Voice Effects.

A Voice with any combination of waveshaper/lowpass/highpass counts as one Voice Effect

Active

The number of active Voice Effects.

Available

How many Voice Effects are available.

19.5 SoundManager Instance Statistics

Real-time statistics per SoundEvent Instance.

Available in Playmode.

Sort By

Which method to sort the list of SoundEvent Instances.

Name

Sorts by alphabetical order

Voices

Sorts by voice count

Plays

Sorts by number of plays

Volume

Sorts by volume

Time

Sorts by last time played

Show

Toggle what information to show about the SoundEvent Instances.

Show Active

How many are currently active.

Show Disabled

How many are currently disabled.

Show Voices

How many voices are currently used.

Show Plays

The number of total plays.

Show Volume

The current average volume.

19.6 AudioListenerDistance Component

If “Override Listener Distance” is enabled in the SoundManager Settings this is a required component in the scene.

The position of the AudioListenerDistance component will determine all distance based calculations (like volume falloff).

While the AudioListener position will be used for spatialization and Angle to Stereo Pan calculations.

Example of usage in a 3rd person or top down game:

Enable "Override Listener Distance" in the SoundManager.

Put the AudioListener on the main camera and the AudioListenerDistance on the player character.

Try changing the Amount slider to find a nice balance between the different positions.

20 SoundManager Functions

The SoundManager is the master object which is used to play sounds and manage global settings.

An instance in the scene is required to play SoundEvents.

You can either add the pre-made prefab called “SoundManager” or add the “Sonity - Sound Manager” component to an empty GameObject in the scene.

Example code:

using UnityEngine;
using Sonity;

public class PlayStopExample : MonoBehaviour {

   
public SoundEvent soundEvent;

   
void PlayExample() {
       
// Plays the SoundEvent at the position of the transform
       
SoundManager.Instance.Play(soundEvent, transform);
   }

    void StopExample() {
       
// Stops the SoundEvent playing at the transform
       
SoundManager.Instance.Stop(soundEvent, transform);
   }
}

20.1 SoundManager.Instance Play

// Plays the SoundEvent at the position of the owner Transform

public void Play(SoundEvent soundEvent, Transform owner)
public void Play(SoundEvent soundEvent, Transform owner, SoundTag localSoundTag)
public void Play(SoundEvent soundEvent, Transform owner, params SoundParameterInternals[] soundParameterInternals)
public void Play(SoundEvent soundEvent, Transform owner, SoundTag localSoundTag, params SoundParameterInternals[] soundParameterInternals)

Parameters

soundEvent

The SoundEvent to play

owner

The owner Transform

localSoundTag

The SoundTag which will determine the Local SoundTag of the SoundEvent

soundParameterInternals

For example SoundParameterVolumeDecibel is used to modify how the SoundEvent is played

20.2 SoundManager.Instance PlayAtPosition

// Plays the SoundEvent at the Vector3 position with another Transform as the owner

public void PlayAtPosition(SoundEvent soundEvent, Transform owner, Vector3 position)
public void PlayAtPosition(SoundEvent soundEvent, Transform owner, Vector3 position, SoundTag localSoundTag)
public void PlayAtPosition(SoundEvent soundEvent, Transform owner, Vector3 position, params SoundParameterInternals[] soundParameterInternals)
public void PlayAtPosition(SoundEvent soundEvent, Transform owner, Vector3 position, SoundTag localSoundTag, params SoundParameterInternals[] soundParameterInternals)

// Plays the SoundEvent at the Transform position with another Transform as the owner

public void PlayAtPosition(SoundEvent soundEvent, Transform owner, Transform position)
public void PlayAtPosition(SoundEvent soundEvent, Transform owner, Transform position, SoundTag localSoundTag)
public void PlayAtPosition(SoundEvent soundEvent, Transform owner, Transform position, params SoundParameterInternals[] soundParameterInternals)
public void PlayAtPosition(SoundEvent soundEvent, Transform owner, Transform position, SoundTag localSoundTag, params SoundParameterInternals[] soundParameterInternals)

Parameters

soundEvent

The SoundEvent to play

owner

The owner Transform

position

The Transform or Vector3 where is should play at (Transform can follow position)

localSoundTag

The SoundTag which will determine the Local SoundTag of the SoundEvent

soundParameterInternals

For example SoundParameterVolumeDecibel is used to modify how the SoundEvent is played

20.3 SoundManager.Instance Stop

// Stops the SoundEvent at the owner Transform

public void Stop(SoundEvent soundEvent, Transform owner, bool allowFadeOut = true)

// Stops the SoundEvent at the position Transform

public void StopAtPosition(SoundEvent soundEvent, Transform position, bool allowFadeOut = true)

// Stops all the SoundEvents at the owner Transform

public void StopAllAtOwner(Transform owner, bool allowFadeOut = true)

// Stops the SoundEvent everywhere

public void StopEverywhere(SoundEvent soundEvent, bool allowFadeOut = true)

// Stops all SoundEvents

public void StopEverything(bool allowFadeOut = true)

Parameters

soundEvent

The SoundEvent to stop

owner

The owner Transform

position

The position Transform

allowFadeOut

If the SoundEvent should be allowed to fade out. Otherwise it is going to be stopped immediately

20.4 SoundManager.Instance Pause and Unpause

// Pauses/unpauses the SoundEvent with the owner Transform locally

public void Pause(SoundEvent soundEvent, Transform owner, bool forcePause = false)

public void Unpause(SoundEvent soundEvent, Transform owner)

// Pauses/unpauses all SoundEvents with the owner Transform locally

public void PauseAllAtOwner(Transform owner, bool forcePause = false)

public void UnpauseAllAtOwner(Transform owner)

// Pauses/unpauses the SoundEvent everywhere locally

public void PauseEverywhere(SoundEvent soundEvent, bool forcePause = false)

public void UnpauseEverywhere(SoundEvent soundEvent)

// Pauses/unpauses the SoundEvent everywhere locally

public void PauseEverything(bool forcePause = false)

public void UnpauseEverything()

Parameters

soundEvent

The SoundEvent to pause/unpause

owner

The owner Transform

forcePause

If the SoundEvent should be paused even if it is set to "Ignore Local Pause"

20.5 SoundManager.Instance Get State, Length and Time

// If playing it returns SoundEventState.Playing

// If paused either locally or globally it returns SoundEventState.Paused

// If not playing, but it is delayed it returns SoundEventState.Delayed

// If not playing and it is not delayed it returns SoundEventState.NotPlaying

// If the SoundEvent or Transform is null it returns SoundEventState.NotPlaying

public SoundEventState GetSoundEventState(SoundEvent soundEvent, Transform owner)

// Returns the length (in seconds) of the AudioClip in the last played AudioSource

// Returns 0 if the InstanceSoundEvent is not playing

// Returns 0 if the SoundEvent or Transform is null

// pitchSpeed determines if it should be scaled by pitch. E.g. -12 semitones will be twice as long

public float GetLastPlayedClipLength(SoundEvent soundEvent, Transform owner, bool pitchSpeed)

// Returns the current time (in seconds) of the AudioClip in the last played AudioSource

// Returns 0 if the InstanceSoundEvent is not playing

// Returns 0 if the SoundEvent or Transform is null

// pitchSpeed determines if it should be scaled by pitch. E.g. -12 semitones will be twice as long

public float GetLastPlayedClipTimeSeconds(SoundEvent soundEvent, Transform owner, bool pitchSpeed)

// Returns the current time (in range 0 to 1) of the AudioClip in the last played AudioSource

// Returns 0 if the InstanceSoundEvent is not playing

// Returns 0 if the SoundEvent or Transform is null

public float GetLastPlayedClipTimeRatio(SoundEvent soundEvent, Transform owner)

// Returns the max length (in seconds) of the SoundEvent (calculated from the longest audioClip)

// Is scaled by the pitch of the SoundEvent and SoundContainer

// Does not take into account random, intensity or parameter pitch

// Returns 0 if the SoundEvent is null

public float GetMaxLength(SoundEvent soundEvent)

// Returns the time (in seconds) since the SoundEvent was played

// Is calculated using the time scale selected in the SoundManager

// Returns 0 if the InstanceSoundEvent is not playing

// Returns 0 if the SoundEvent or Transform is null

public float GetTimePlayed(SoundEvent soundEvent, Transform owner)

// Returns the Transform of the SoundManager

public Transform GetSoundManagerTransform()

Parameters

soundEvent

The SoundEvent to get length or time from

owner

The owner Transform

pitchSpeed

Determines if it should be scaled by pitch. E.g. -12 semitones will be twice as long

20.6 SoundManager.Instance Get Spectrum Data

// Provides a block of spectrum data from AudioSources

public void GetSpectrumData(SoundEvent soundEvent, Transform owner, ref float[] samples, int channel, FFTWindow window, SpectrumDataFrom spectrumDataFrom)

Parameters

soundEvent

The SoundEvent to get the spectrum data from

owner

The owner Transform

samples

The array to populate with audio samples. Its length must be a power of 2

channel

The channel to sample from

window

The FFTWindow type to use when sampling

spectrumDataFrom

Where to get the spectrum data from

20.7 SoundManager.Instance Load or Unload Audio Data

// Loads the audio data of any AudioClips assigned to the SoundContainers of the SoundEvent

public void LoadAudioData(SoundEvent soundEvent)

// Unloads the audio data of any AudioClips assigned to the SoundContainers of the SoundEvent

public void UnloadAudioData(SoundEvent soundEvent)

20.8 SoundManager.Instance 2D Play

Useful if you want to play SoundEvents without passing an owner.

// Plays the SoundEvent with the 2D Transform as owner

// Useful to play e.g. UI or other 2D sounds without having to pass a Transform

// To make the sound 2D you still need to disable distance and set spatial blend to 0 in the SoundContainer

public void Play2D(SoundEvent soundEvent)
public void Play2D(SoundEvent soundEvent, SoundTag localSoundTag)
public void Play2D(SoundEvent soundEvent, params SoundParameterInternals[] soundParameterInternals)
public void Play2D(SoundEvent soundEvent, SoundTag localSoundTag, params SoundParameterInternals[] soundParameterInternals)

// Plays the SoundEvent at the position with the 2D Transform as owner (Useful for UnityEvents because it only has one parameter)

public void Play2DAtPosition(Vector3 position)

public void Play2DAtPosition(Transform position)

Parameters

soundEvent

The SoundEvent to play

localSoundTag

The SoundTag which will determine the Local SoundTag of the SoundEvent

soundParameterInternals

For example SoundParameterVolumeDecibel is used to modify how the SoundEvent is played

position

The Transform or Vector3 where is should play at (Transform can follow position)

20.9 SoundManager.Instance 2D Stop

// Stops the SoundEvent at the 2D Transform

public void Stop2D(SoundEvent soundEvent, bool allowFadeOut = true)

// Stops all SoundEvents at the 2D Transform

public void StopAll2D(Transform owner, bool allowFadeOut = true)

Parameters

soundEvent

The SoundEvent to stop

allowFadeOut

If the SoundEvent should be allowed to fade out. Otherwise it is going to be stopped immediately

20.10 SoundManager.Instance 2D Pause and Unpause

// Pauses/unpauses the SoundEvent at the 2D Transform locally

public void Pause2D(SoundEvent soundEvent, bool forcePause = false)

public void Unpause2D(SoundEvent soundEvent)

// Pauses/unpauses all SoundEvents at the 2D Transform locally

public void PauseAll2D(bool forcePause = false)

public void UnpauseAll2D()

Parameters

soundEvent

The SoundEvent to pause/unpause

forcePause

If the SoundEvent should be paused even if it is set to "Ignore Local Pause"

20.11 SoundManager.Instance 2D Get State, Length and Time

// Uses the 2D owner Transform

// If playing it returns SoundEventState.Playing

// If paused either locally or globally it returns SoundEventState.Paused

// If not playing, but it is delayed it returns SoundEventState.Delayed

// If not playing and it is not delayed it returns SoundEventState.NotPlaying

// If the SoundEvent or Transform is null it returns SoundEventState.NotPlaying

public SoundEventState Get2DSoundEventState(SoundEvent soundEvent)

// Uses the 2D owner Transform

// Returns the length (in seconds) of the AudioClip in the last played AudioSource

// Returns 0 if the InstanceSoundEvent is not playing

// Returns 0 if the SoundEvent or Transform is null

// pitchSpeed determines if it should be scaled by pitch. E.g. -12 semitones will be twice as long

public float Get2DLastPlayedClipLength(SoundEvent soundEvent, bool pitchSpeed)

// Uses the 2D owner Transform

// Returns the current time (in seconds) of the AudioClip in the last played AudioSource

// Returns 0 if the InstanceSoundEvent is not playing

// Returns 0 if the SoundEvent or Transform is null

// pitchSpeed determines if it should be scaled by pitch. E.g. -12 semitones will be twice as long

public float Get2DLastPlayedClipTimeSeconds(SoundEvent soundEvent, bool pitchSpeed)

// Uses the 2D owner Transform

// Returns the current time (in range 0 to 1) of the AudioClip in the last played AudioSource

// Returns 0 if the InstanceSoundEvent is not playing

// Returns 0 if the SoundEvent or Transform is null

public float Get2DLastPlayedClipTimeRatio(SoundEvent soundEvent)

// Uses the 2D owner Transform

// Returns the time (in seconds) since the SoundEvent was played

// Is calculated using the time scale selected in the SoundManager

// Returns 0 if the InstanceSoundEvent is not playing

// Returns 0 if the SoundEvent or Transform is null

public float Get2DTimePlayed(SoundEvent soundEvent)

// Returns the owner Transform used by Play2D() etc

public Transform Get2DTransform()

Parameters

soundEvent

The SoundEvent to get length or time from

pitchSpeed

Determines if it should be scaled by pitch. E.g. -12 semitones will be twice as long

20.12 SoundManager.Instance Music Play

Useful if you want to play music with automatic stopping of the old music when playing a new song.

// Plays the SoundEvent at the SoundManagers music Transform

public void PlayMusic(SoundEvent soundEvent, bool stopAllOtherMusic = true, bool allowFadeOut = true)

public void PlayMusic(SoundEvent soundEvent, bool stopAllOtherMusic = true, bool allowFadeOut = true, params SoundParameterInternals[] soundParameterInternals)

Parameters

soundEvent

The SoundEvent to play

stopAllOtherMusic

If all other SoundEvents played at the SoundManager music Transform should be stopped

allowFadeOut

If the other stopped SoundEvent should be allowed to fade out. Otherwise they are going to be stopped immediately

soundParameterInternals

For example SoundParameterVolumeDecibel is used to modify how the SoundEvent is played

20.13 SoundManager.Instance Music Stop

// Stops the SoundEvent playing at the Music Transform

public void StopMusic(SoundEvent soundEvent, bool allowFadeOut = true)

// Stops all the SoundEvents playing at the Music Transform

public void StopAllMusic(bool allowFadeOut = true)

Parameters

soundEvent

The SoundEvent to stop

allowFadeOut

If the other stopped SoundEvent should be allowed to fade out. Otherwise they are going to be stopped immediately

20.14 SoundManager.Instance Music Pause and Unpause

// Pauses/unpauses the SoundEvent at the Music Transform locally

public void PauseMusic(SoundEvent soundEvent, bool forcePause = false)

public void UnpauseMusic(SoundEvent soundEvent)

// Pauses/unpauses all SoundEvents at the Music Transform locally

public void PauseAllMusic(bool forcePause = false)

public void UnpauseAllMusic()

Parameters

soundEvent

The SoundEvent to pause/unpause

forcePause

If the SoundEvent should be paused even if it is set to "Ignore Local Pause"

20.15 SoundManager.Instance Music Get State, Length and Time

// Uses the Music owner Transform

// If playing it returns SoundEventState.Playing

// If paused either locally or globally it returns SoundEventState.Paused

// If not playing, but it is delayed it returns SoundEventState.Delayed

// If not playing and it is not delayed it returns SoundEventState.NotPlaying

// If the SoundEvent or Transform is null it returns SoundEventState.NotPlaying

public SoundEventState GetMusicSoundEventState(SoundEvent soundEvent)

// Uses the Music owner Transform

// Returns the length (in seconds) of the AudioClip in the last played AudioSource

// Returns 0 if the InstanceSoundEvent is not playing

// Returns 0 if the SoundEvent or Transform is null

// pitchSpeed determines if it should be scaled by pitch. E.g. -12 semitones will be twice as long

public float GetMusicLastPlayedClipLength(SoundEvent soundEvent, bool pitchSpeed)

// Uses the Music owner Transform

// Returns the current time (in seconds) of the AudioClip in the last played AudioSource

// Returns 0 if the InstanceSoundEvent is not playing

// Returns 0 if the SoundEvent or Transform is null

// pitchSpeed determines if it should be scaled by pitch. E.g. -12 semitones will be twice as long

public float GetMusicLastPlayedClipTimeSeconds(SoundEvent soundEvent, bool pitchSpeed)

// Uses the Music owner Transform

// Returns the current time (in range 0 to 1) of the AudioClip in the last played AudioSource

// Returns 0 if the InstanceSoundEvent is not playing

// Returns 0 if the SoundEvent or Transform is null

public float GetMusicLastPlayedClipTimeRatio(SoundEvent soundEvent)

// Uses the Music owner Transform

// Returns the time (in seconds) since the SoundEvent was played

// Is calculated using the time scale selected in the SoundManager

// Returns 0 if the InstanceSoundEvent is not playing

// Returns 0 if the SoundEvent or Transform is null

public float GetMusicTimePlayed(SoundEvent soundEvent)

// Returns the owner Transform used by PlayMusic() etc

public Transform GetMusicTransform()

Parameters

soundEvent

The SoundEvent to get length or time from

pitchSpeed

Determines if it should be scaled by pitch. E.g. -12 semitones will be twice as long

20.16 SoundManager.Instance Global Pause and Unpause

// Pauses the all SoundEvents except those who are set to "Ignore Global Pause"

public void SetGlobalPause()

// Unpauses the all SoundEvents except those who are set to "Ignore Global Pause"

public void SetGlobalUnpause()

// Returns if Global Pause is enabled

public bool GetGlobalPaused()

20.17 SoundManager.Instance Global Volume

// Sets a global volume of all sounds in decibels using AudioListener.volume, ranging from NegativeInfinity dB to 0 dB

public void SetGlobalVolumeDecibel(float volumeDecibel)

// Returns the global volume in decibels, ranging from NegativeInfinity dB to 0 dB

public void SetGlobalVolumeRatio(float volumeRatio)

// Sets a global volume of all sounds in linear scale using AudioListener.volume, ranging from 0 to 1

public float GetGlobalVolumeDecibel()

// Returns the global volume in linear scale, ranging from 0 to 1

public float GetGlobalVolumeRatio()

20.18 SoundManager.Instance Global SoundTag

// Sets the global SoundTag

public void SetGlobalSoundTag(SoundTag soundTag)

// Returns the global SoundTag

public SoundTag GetGlobalSoundTag()

20.19 SoundManager.Instance Global Distance Scale

// Sets the global distance scale (default is a scale of 100 units)

public void SetGlobalDistanceScale(float distanceScale)

// Returns the global distance scale

public float GetGlobalDistanceScale()

20.20 SoundManager.Instance Speed Of Sound

// Set if speed of sound should be active

public void SetSpeedOfSoundEnabled(bool speedOfSoundEnabled)

// Set the speed of sound scale

// The default is a multiplier of 1 (by the base value of 340 unity units per second)

public void SetSpeedOfSoundScale(float speedOfSoundScale)

// Returns the speed of sound scale

public float GetSpeedOfSoundScale()

20.21 SoundManager.Instance Voice Limit

// Sets the Voice limit

public void SetVoiceLimit(int voiceLimit)

// Returns the Voice limit

public int GetVoiceLimit()

// Sets the VoiceEffect limit

public void SetVoiceEffectLimit(int voiceEffectLimit)

// Returns the VoiceEffect limit

public int GetVoiceEffectLimit()

20.22 SoundManager.Instance Disable Playing Sounds

// Disables/enables all the Play functionality

public void SetDisablePlayingSounds(bool disablePlayingSounds)

// If the Play/PlayAtPosition functionality is disabled

public bool GetDisablePlayingSounds()