informa
3 min read
Featured Blog

Richer audio in Unity with Fabric. Part 1

The first in a series of how-to's for Tazman-Audio's Fabric, an audio toolset for Unity.

Tazman-Audio's Fabric is a toolset that facilitates creating sophisticated audio for your Unity games, within Unity itself. For an overview of its features, visit Tazman-Audio's website, or you can take a look at the documentation here (PDF).

This first how-to covers setting up Fabric in Unity so that you can trigger a simple sound via code. A sort of 'hello-world' tutorial.

First we import the Fabric package.

Once Fabric is in your project, from the new Fabric menu, create a FabricManager. At the time of writing the FabricManager object gets assigned the name 'Audio' when you add it this way.

The items in the Fabric menu are shortcuts that add empty game objects to your scene that have Fabric components attached. The objects are named after the components they carry. If you need to access just the Fabric components you can do so via the Fabric subsection in your component menu.

The manager object will be the parent of all the other Fabric objects in your project, which get nested within it.

With the FabricManager object selected, create an AudioComponent object as shown, it will be added as a child of the manager object. An AudioComponent can be considered Fabric's most atomic element. By attaching an AudioComponent you enable an object to play a single sound file in response to events in the Fabric system.

With the AudioComponent object selected, drag a sound file into the AudioClip field as shown. You might also want to rename your object to reflect the sound it's associated with. The convention I've been using is to append this kind of information to the auto-generated Fabric names. Since I'm adding a 'winning flourish' sound, I might call this game object AudioComponent_win for example.

To trigger the sound we need to set up a Fabric event for it to respond to. With the AudioManager component selected, add a new event to the Event List by typing the name of the new event into the field next to the Add button, and then clicking Add. The new event will appear in the list immediately. I've added an event called win.

Next we'll get the AudioComponent to respond to the win event. With the AudioComponent object selcted add a Listener component as shown.

In the Event Name dropdown, select the Event you'd like the sound to be triggered by.

Now the sound can be triggered by code as shown in the following image. The PostEvent method can be called with only the event name as an argument if you like. If you call it this way, the origin of the sound in your game world will be the AudioManager game object. For a game where you don't want to work with positional audio (eg. a 2d game) you might want to consider attaching the AudioManager object as a child of the Main Camera.

Alternatively you can pass a second argument that specifies which game object you'd like the sound to eminate from.

That's all for now. In part two I'll cover randomisation and layering of sounds in Fabric.

Latest Jobs

Treyarch

Playa Vista, California
6.20.22
Audio Engineer

Digital Extremes

London, Ontario, Canada
6.20.22
Communications Director

High Moon Studios

Carlsbad, California
6.20.22
Senior Producer

Build a Rocket Boy Games

Edinburgh, Scotland
6.20.22
Lead UI Programmer
More Jobs   

CONNECT WITH US

Register for a
Subscribe to
Follow us

Game Developer Account

Game Developer Newsletter

@gamedevdotcom

Register for a

Game Developer Account

Gain full access to resources (events, white paper, webinars, reports, etc)
Single sign-on to all Informa products

Register
Subscribe to

Game Developer Newsletter

Get daily Game Developer top stories every morning straight into your inbox

Subscribe
Follow us

@gamedevdotcom

Follow us @gamedevdotcom to stay up-to-date with the latest news & insider information about events & more