ambient_generic
Jump to navigation
Jump to search

Important:The majority of sound properties that can be set with this entity are intended to only apply to raw sounds. Since soundscripts are defined in text files where their desired sound properties are specified, soundscripts ignore this entity's settings by design. Note that this also means that soundscripts have the advantage of being able to change sound files and properties in a map without having to recompile it. The same applies to soundscapes.
Tip:This entity can be parented if the
Bug:The
Workaround:Use SourceEntityName
Bug:
Counter-Strike: Source must be activated with a logic_auto, or they will stop playing once the first round starts. [todo tested in ?]
Bug:Killing this entity while a looped sound is playing will make it play forever for the entire map duration. This also may cause looping sounds to stack up and eventually overflow the sound limit (detailed below), even if they aren't audible. [todo tested in ?]
Code Fix:Problems with sounds being unstoppable can be avoided by adding this C++ code to your mod.
Bug:Looping sounds might become attached to certain players when they are not supposed to. E.g., if you are away from a sound, and a player near the sound dies and then spectates you, the sound may become attached to you. The exact consistency/behavior of this bug is still unknown. [todo tested in ?]
Bug:Too many
) is hit. Due to another bug,
Workaround:Use env_soundscapes (which count towards a different static limit of 64) where possible and forcefully disable any sounds that aren't necessary to play yet. The amount of sounds currently playing can be visualized with the
Bug:Looping sounds using LFO cannot be stopped via the
Note:The behavior of sound is different for mono and stereo. Stereo sounds only fade in and out (they are already using surrounding information built into them). Mono sounds are processed by the audio engine to sound like they are coming from a specific position. These behaviors can be overridden by using Sound Characters.
Note:In Half-Life 2, since November 26, 2024 update (post-20th anniversary), ambient_generic (used for music) will continue to play on the next map. This can be enabled/disabled through save_transition_music ConVar.

ambient_generic
is a point entity available in all Source games.
![]() |
---|
CAmbientGeneric |
![]() |
This entity plays a sound, either once or on loop and either globally or from a location in the world (spatial).
Use it to play and control a
- soundscript sound,
- a raw WAV, MP3, OGG (only in
), or FLAC (only in
) file, or
- a scripted_sentence.
All three can be browsed with the Hammer Sound Browser, being named "Game Sounds", "Raw" and "Scenes", in this order.

Notes/Bugs/Limitations

parentname
keyvalue or SetParent
input is used, even though they aren't listed in the FGD.
ambient_generic
will not update its position while the sound is playing if it is parented. [todo tested in ?]

ambient_generic
s used to play looping sounds in 




ambient_generic
s playing at once will cause the sound engine to become corrupted globally and potentially cause extreme lag! This occurs if the internal entity sound limit of 64 (32 in 
ambient_generic
s still "play" when outside the maximum distance, even if not audible to the client. Use snd_show 1
to visualize sounds considered "active". Too many yellow-colored sound names is a bad sign. [todo tested in ?]
snd_show
command.
StopSound
input. [todo tested in ?]

Keyvalues
- Sound Name (message) <sound>
- The sound to play, i. e. either a soundscript name or a direct path to a sound file relative to
<moddir>/sounds/
. Direct paths to a sound file can be prefixed with sound characters. For scripted_sentences, type!
followed by the sentence name, for example!COMBINE_THROW_GRENADE4
. - Max Audible Distance (radius) <float>
- Rough (!) distance in units at which the sound is audible for a client. Volume fades to nothing as the player approaches this distance but it cannot be expected to be exact. This determines the soundlevel for raw sounds, which is
SNDLVL_70dB
at the default value of 1250 units. DSP may affect the actual audible radius, too. The sound system still actually plays the sound outside the distance, which is why soundscapes may be a better solution for environmental sounds. - SourceEntityName (SourceEntityName) <targetname>
- If specified, the sound will play from this entity instead of the
ambient_generic
. If the target is an NPC capable of lipsynching, and phoneme data is found within the sound, the target will lip-sync to it.Bug:If the
ambient_generic
isKill
ed, the sound will play at the origin of the map (at 0,0,0). [todo tested in ?]Bug:The entity must be spawned at map start, or else the sound will play at the location of the
ambient_generic
. [todo tested in ?]Bug:Using
AddOutput
to assign theSourceEntityName
after the entity spawns does not work. [todo tested in ?]Bug:Multiple
ambient_generic
s won't stack on the same entity. [todo tested in ?]Note:An
ambient_generic
will only play from a single entity. If there are multiple entities with the same target name, the sound will only play from the first one it finds. - Volume (health) <integer 0–10>
- How loud to play the sound. 0 is silent and 10 is normal. Default is 10.
Tip:This keyvalue doesn't allow decimals, but the
Volume
input does.Tip:Sounds may be hard to hear even at full volume. Naming custom sounds according to the soundmixer can be used to make them naturally louder (or quieter).
Bug:The sound does not play at all if the volume is 0. [todo tested in ?]
- Start Volume (volstart) <integer 0–10>
- Fade in time in seconds (fadeinsecs) <integer 0–100>
- Fade out time in seconds (fadeoutsecs) <integer 0–100>
- How long to spend fading in and out, and what volume to start at. Default is no fading.
- Pitch (pitch) <integer 0–255>
- Pitch, where 1 is low, 100 is normal, and 255 is high.
Bug:Very high or very low values can cause other sounds to be distorted. [todo tested in ?]
- Start pitch (pitchstart) <integer 0–255>
- Spin up time (spinup) <integer 0–100>
- Spin down time (spindown) <integer 0–100>
- How long to spend spinning pitch up/down at the start/end of playback, and what pitch to start at. Default is no spinning.
- Dynamic Presets (preset) <choices>
- Various DSP effects that can be applied.
- LFO type (lfotype) <integer>
- Type of Low Frequency Oscillation to employ.
- 0. Off (default)
- 1. Square Wave (alternate between low and high)
- 2. Triangle Wave (crossfade between high and low)
- 3. Random
- LFO rate (lforate) <integer 0–1000>
- How frequently the LFO effect repeats itself.
- LFO modulation - pitch (lfomodpitch) <integer 0–100>
- Affects the sound pitch or vibrato. Higher numbers change the pitch more; warbling singers use little, police sirens use a lot.
- LFO modulation - volume (lfomodvol) <integer 0–100>
- Affects the volume of the sound, causing it to "pulse." Similar to tremolo. At a really high rate, this can make the same effect as talking through fan blades.
- Incremental Spinup Count (cspinup) <integer>
- Appears to be a intended to increase pitch in time with
ToggleSound
inputs.Bug:Non-functional. [todo tested in ?]
- m_bDontModifyPitchVolOnSpawn (m_bDontModifyPitchVolOnSpawn) <choices> (only in
)
- When the 'Start Silent' flag is left unchecked, a SOUNDSCRIPTED ambient_generic will first pull its pitch & volume values from inside the entity itself upon map load/spawn, and NOT from what's dictated in the actual soundscript. This option, when enabled, will prevent this from happening and ensure no discontinuity occurs when toggling the sound off and on again. (Set to Disabled by default)
- 0: Disabled
- 1: Enabled
- Name (targetname) <string>
- The name that other entities refer to this entity by, via Inputs/Outputs or other keyvalues (e.g.
parentname
ortarget
).
Also displayed in Hammer's 2D views and Entity Report.See also: Generic Keyvalues, Inputs and Outputs available to all entities
Inputs
- Pitch <integer>
- Sets the sound pitch, expressed as a range from 1 to 255, where 100 is the sound's original pitch.
Bug:Pitch will play the sound without informing the rest of the entity. This makes looping sounds unstoppable!. [todo tested in ?]
- PlaySound
- Starts the sound.
- StopSound
- Stops a looping sound. Does not stop a non-looping sound; however, a non-looping sound can be stopped by using the Volume input with a value of 0.
Code Fix:If necessary, you can allow this input to stop a non-looping sound via C++.
- ToggleSound
- Toggles a looping sound between playing and stopped. Behaves like
PlaySound
if the sound doesn't loop.
- Volume <float>
- Plays the sound at a volume from 0 to 10, where 10 is the loudest.
Bug:Volume will play the sound without informing the rest of the entity. This makes looping sounds unstoppable! It is speculated that the input is supposed to change the volume at which the
ambient_generic
plays its sound when prompted by other inputs, not play it by itself. [todo tested in ?]Note:Setting the volume to 0 will cause the sound to pause, rather than play silently.
- FadeIn <integer>
- Fades the sound up to full volume over a specified number of seconds, with a range from 0 to 100 seconds.
Note:In
Portal 2 it is necessary for the sound to get faded out at least once before this input has any effect.
- FadeOut <integer>
- Fades the sound to silence over a specified number of seconds, with a range from 0 to 100 seconds.
Flags
Play everywhere : [1]
- Sound plays at a constant volume, no matter how far away the listener is from the sound source. This applies only to raw sound, not to soundscripts. Todo: How does this interact with env_microphone sound detection?
Start Silent : [16]
- The map will start without this sound playing. Enabled by default.
Bug:Looping sounds that do not start silent cannot be controlled! [todo tested in ?]
Is NOT Looped : [32]
- Changes how the
ambient_generic
handles stopping and starting playback. In fact, this flag doesn't let you decide whether or not to loop the sound file, instead the sound system needs it to be set to the right value to start and stop the sound properly. Sound files with loop markers always loop, files without never loop. If a sound doesn't do what you expect, then the sound file probably has no loop markers although it should, or vice versa.Bug:In multiplayer, if this flag is NOT set on a non-looping sound and any player's connection is briefly dropped, the sound will play again for everyone in the server! This is due to the entity recalculating it's networking state and re-sending it to that player, but it unfortunately sends it to everyone else as well. Looping sounds don't have this problem as they do not restart while already playing. [todo tested in ?]
Do NOT Pause when game is Paused : [64] (only in )
- Don't pause sound when game is paused.
See also
- Sound and Music
- Adjust ambient_generic volume higher than 10 (Advanced Mapping Tutorial)
- env_soundscape - used to play many ambient/background sounds from a single entity via a script.
- music_track - used to dynamically play music in
Black Mesa.
- Looping a Sound - which requires modifying the actual WAV file
- Setting up
ambient_generic
s in Counter-Strike: Source usinglogic_auto
- a substitute for creating a properenv_soundscape
.