Table of Contents

Audio emitters

Beginner Programmer Designer

Audio emitter components emit audio used to create spatialized audio. You can add them to any entity.

The pitch and volume of the sound changes as the audio listener moves closer to and away from the audio emitter.

Note

You need at least one AudioListenerComponent in the scene to hear audio from audio emitters.

1. Set up an audio emitter asset

  1. In the Scene view, select an entity you want to be an audio emitter.

    Select an entity

  2. In the Property Grid, click Add component and select Audio Emitter.

    Add AudioEmitter Component

    Now we need to add audio to the emitter.

  3. Under Audio Emitter, click Green plus button (Add) and specify a name for the audio.

    Add new sound entry

  4. From the Asset View, drag and drop an audio asset to the audio you just added:

    Drag and drop an audio asset

    Alternatively, click Hand icon (Select an asset).

    Pick up an asset

    Then choose an audio asset:

    Select audio  asset

  5. Repeat steps 3 and 4 to add as many audio assets as you need.

  6. Configure the properties for this audio emitter.

    Audio emitter properties

Property Description
Use HRTF Enable head-related transfer function (HRTF). With this enabled, sounds appear to come from a specific point in 3D space, synthesizing binaural audio. For more information, see HRTF.
Directional factor How directional the audio is, from 0 (min) to 1 (max). If set to 0, the audio is emitted from all directions. You can control this with a slider or number value.
Environment The reverb type for the audio, simulating reverberation of real environments (small, medium, large, or outdoors).

2. Create a script to play the audio

Now we need to create a script to play and configure the audio asset.

  1. In your script, instantiate AudioEmitterSoundController for each sound you want to use in the script.

    For example, say we have two sounds, MySound1 and MySound2:

     AudioEmitterComponent audioEmitterComponent = Entity.Get<AudioEmitterComponent>();
     AudioEmitterSoundController mySound1Controller = audioEmitterComponent["MySound1"];
     AudioEmitterSoundController mySound2Controller = audioEmitterComponent["MySound2"];
    
  2. Use the following AudioEmitterSoundController properties and methods to play and configure the audio:

Property / method Description
IsLooping Loops audio. Has no effect if PlayAndForget() is set to true.
Pitch Gets or sets sound pitch (frequency). Use with caution for spatialized audio.
PlayState Gets the current state of the audio emitter sound controller.
Volume Volume of the audio.
Pause() Pauses audio.
Play() Plays audio.
PlayAndForget() Plays audio once, then clears the memory. Useful for short sounds such as gunshots. Overrides IsLooping.
Stop() Stops audio.

For example:

mySound1Controller.IsLooping = true;
mySound1Controller.Pitch = 2.0f;
mySound1Controller.Volume = 0.5f;
mySound1Controller.Play();

This sound will loop at double the original pitch and half the original volume. For more information, see the AudioEmitterSoundController Stride API documentation.

3. Add the script to the audio emitter entity

Game Studio lists the script as a component under Add component. Add the script to the audio emitter entity.

  1. In the Scene view, select an entity you want to be an audio emitter.

    Select an entity

  2. Click Add component and select the script.

    Add audio script

See also