Playing Audio

This page will explain how to play audio events in Enter the Gungeon, with a primary focus on playing vanilla sounds.

Playing a Sound

Playing a sound in Enter the Gungeon is done through the AkSoundEngine class, which accepts 'events' (string identifiers related to specific sounds or groups of sounds) and plays them from a given gameObject.

AkSoundEngine.PostEvent("Play_OBJ_med_kit_01", example.gameObject);

The above line of code plays the event Play_OBJ_med_kit_01 (Which corresponds to the SFX of the Medkit item) on a gameObject, written here as the gameObject of a generic example object or component.

Sounds can be played at any point in your code, as long as the gameObject provided for the sound to play on actually exists. If the gameObject provided to host the sound does not exist, the game will crash, so be careful!

Some examples of playing audio might be;

  • Playing a special sound in the DoEffect method of an active item- to give its activation more flair.

  • Playing a sound effect when a projectile hits an enemy, to signify that the projectile is doing something special to that enemy.

  • Playing a sound effect in the midst of an enemy behaviour to make the behaviour more impactful.

Playing a Looping Sound

Not all sounds are simply played once and go away on their own, however. Some audio is set to loop indefinitely and must be manually stopped by playing a special stop event.

AkSoundEngine.PostEvent("Play_ANM_Gull_Loop_01", example.gameObject);

yield return new WaitForSeconds(5f);

AkSoundEngine.PostEvent("Stop_ANM_Gull_Loop_01", example.gameObject);

In the above example, the sound Play_ANM_Gull_Loop_01 is played on an example gameobject. This code is assumed to be running in a coroutine, allowing the use of the WaitForSeconds class in Unity to pause the coroutine for 5 seconds.

After the five seconds is up, the event Stop_ANM_Gull_Loop_01 is played to end the looping noise.

Last updated

Was this helpful?