From Valve Developer Community
Revision as of 06:28, 28 July 2021 by MrFunreal (talk | contribs) (Entity description: added note about using soundscript names instead or "raw" sounds)
Jump to: navigation, search
Русский 简体中文

ambient_generic is a point entity available in all Source games.

Entity description

Ambient generic.png

It plays a sound, either once or on loop, and either from a location in the world or globally.

Use it to play and control a soundscript sound, a raw .wav sample or a scripted sentence.

Tip.png Tip: This entity can be parented if the "parentname" keyvalue or SetParent input is used, even though its not listed in the FGD.
Bug.png Bug: ambient_generics used to play looping sounds in Counter-Strike Source must be activated with a logic_auto or they will stop playing once the first round starts.
Bug.png Bug: Problems with sounds being unstoppable (detailed below) can be avoided by adding this C++ code to your mod.
Bug.png Bug: Killing this entity while a looped sound is playing will make it play forever for the entire map duration.
Bug.png Bug: The ambient_generic will not update its position while the sound is playing if parented.
Bug.png Bug: Looping sounds might become attached to certain players when not supposed to. E.g. you are away from a sound, a player near the sound dies and then spectates you, the sound will become attached to yourself. The exact consistency/behavior of this bug is still unknown.
Bug.png Bug: Too many ambient_generics playing at once will cause other the sound engine to become corrupted globally and cause extreme lag! This occurs if the internal entity sound limit of 64 (32 in Counter-Strike: Global Offensive) is hit. Due to another bug, ambient_generics still "play" when outside the distance, even if not audible to the client. The workaround is to 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 snd_show command.
Note.png Note: The behavior of sound is different for mono and stereo. Stereo sounds are only fading in and out (they are already using surround information build into them). Mono sounds sound like are coming from specific position.
Note.png Note: Using the Soundscript name of a sound, as opposed to its "raw" audio file will apply all the soundscript settings.
Example: In L4D2, the soundscript of dlc.Generator_start_run_loop is set to play everywhere but at lower volume even if "Play everywhere" is not set. But using its raw sound Generator_start_run_loop.wav works as intended.


Sound Name (message) <string>
The soundscript name of, or direct path to, the sound to play. For scripted sentences, type "!" followed by the sentence name. (Example: !COMBINE_THROW_GRENADE4)
Note.png Note: Music should be flagged as music with the '#' character before the sound path (e.g. #music/song01.wav) and placed in "sound/music/..." directory in order for it to be affected by the "Music Volume" slider in the options menu.
Max Audible Distance <float>
Maximum distance in units at which the sound plays for a client.
Bug.png Bug: The sound still actually plays outside the distance.
Bug.png Bug: Sounds may still be audible far outside the distance due to DSP.
Note.png Note: Volume fades to nothing as the player approaches this distance, which can make it seem as if the sound stops playing too early.
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.png Bug: If the ambient_generic is killed, the sound will play at the origin of the map (at 0,0,0).
Bug.png Bug: Entity must be spawned at map start, or else sound will play at the location of the ambient_generic. Using AddOutput to assign the SourceEntityName after the entity spawns does not work.
Bug.png Bug: Multiple ambient_generics won't stack on the same entity.
Note.png Note: Ambient_generics 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. (Only tested in Team Fortress 2)
Volume <int 0-10>
How loud to play the sound. 0 is silent and 10 is normal. Default is 10.
Tip.png Tip: This keyvalue doesn't allow decimals, but the Volume input does.
Bug.png Bug: The sound does not play at all if the volume is 0.
Start Volume <int 0-10>
Fade in time in seconds <int 0-100>
Fade out time in seconds <int 0-100>
How long to spend fading in and out, and what volume to start at. Default is no fading.
Pitch <int 1-255>
Pitch, where 1 is low, 100 is normal, and 255 is high.
Bug.png Bug: Very high or very low values can cause other sounds to be distorted.
Start pitch <int 1-255>
Spin up time <int 0-100>
Spin down time <int 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 <choices>
Various DSP effects that can be applied.
LFO type <int>
Type of Low Frequency Oscillation to employ.
  • Off (default)
  • Square Wave (alternate between low and high)
  • Triangle Wave (crossfade between high and low)
  • Random
LFO rate <int 0-1000>
How frequently the LFO effect repeats itself.
LFO modulation - pitch <int 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 <int 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 <int>
Appears to be a intended to increase pitch in time with ToggleSound inputs, but:
Bug.png Bug: Non-functional.


Name (targetname) <string>
The name that other entities use to refer to this entity.
Parent (parentname) <targetname>
Maintain the same initial offset to this entity. An attachment point can also be used if separated by a comma at the end. (parentname [targetname],[attachment])
Tip.png Tip: Entities transition to the next map with their parents
Tip.png Tip: phys_constraintcan be used as a workaround if parenting fails.
Global Entity Name (globalname) <string>
When the player transitions to a new map, entities in the new map with matching globalnames will have their previous map's states copied over to it.
Origin (X Y Z) (origin) <coordinates>
The position of this entity's center in the world. Rotating entities typically rotate around their origin.
Note.png Note: Hammer does not move the entities accordingly only in the editor.
Pitch Yaw Roll (X Y Z) (angles) <angle>
This entity's orientation in the world. Pitch is rotation around the Y axis, yaw is the rotation around the Z axis, roll is the rotation around the X axis.
Note.png Note: This works on brush entities, although Hammer doesn't show the new angles.
Response Contexts (ResponseContext) <string>
Pre-defined response system contexts; Format is [key]:[value],[key]:[value],...and so on.
Tip.png Tip: Can also be filtered for or against!
Classname (classname) <string> !FGD
Determines the characteristics of the entity before it spawns.
Tip.png Tip: Changing classnames using theAddOutputinput can still influence the game's code, like making the classname match one element in the S_PreserveEnts list will make the entity persists on new rounds!
Flags (spawnflags) <integer> !FGD
Toggles exclusive features of an entity, its specific number is determined by the combination of flags added.
Effects (effects) <integer> !FGD
Combination of effect flags to use.
Hammer ID (hammerid) <integer> !FGD
The entity's unique Hammer ID that's auto-generated on map compiles. Mainly used by plugins or debugging commands (like theent_keyvaluecommand). Run-time spawned entities don't have a Hammer ID.
Entity Scripts (vscripts) <scriptlist> (in all games since Left 4 Dead 2)
Space delimited list of VScript files (without file extension) that are executed after all entities have spawned. The scripts are all executed in the same script scope, later ones overwriting any identical variables and functions.
Script think function (thinkfunction) <string> (in all games since Left 4 Dead 2)
Name of a function in this entity's script which will be called automatically every 100 milliseconds (ten times a second) for the duration of the script. It can be used to create timers or to simulate autonomous behavior. The return value (if present) will set the time until the next call. Try to avoid expensive operations in this function, as it may cause performance problems.
Lag Compensation (LagCompensate) <boolean> (in all games since Left 4 Dead 2) !FGD
Set to Yes to lag compensate this entity. Should be used very sparingly!
Disable for Xbox 360 (disableX360) <boolean> (in all games since Left 4 Dead 2) !FGD
If this entity should automatically be given the 'Disable' input on the Xbox 360 version of Source.
Is Automatic-Aim Target (is_autoaim_target) <boolean> (in all games since Counter-Strike: Global Offensive) !FGD
If set to 1, this entity will slow down aiming movement for consoles and joystick controllers when the entity is under the crosshairs.


  • 1: Play everywhere
    Sound plays at a constant volume, no matter how far away the listener is from the sound source. To do: How does this interact with env_microphone sound detection?
Bug.png Bug: This flag is broken at engine level for Soundscripts. It will only work when a sound is played with its raw filename.
  • 16: Start Silent
The map will start without this sound playing. Enabled by default.
Bug.png Bug: Looping sounds that do not start silent cannot be controlled!
  • 32: Is NOT Looped
Changes how the ambient_generic handles stopping and starting playback. It won't stop a sound that loops from looping, but it is still very important to set it to the right value. You might not be able to stop and/or start the sound if it isn't!
Bug.png Bug: Having this option ticked while using a looped sound WILL prevent you from controlling it!


Pitch <int>
Sets the sound pitch, expressed as a range from 1 to 255, where 100 is the sound's original pitch.
Bug.png Bug: Pitch will play the sound without informing the rest of the entity. This makes looping sounds unstoppable!.
Starts the sound.
Stops a looping sound. Does not stop a non-looping sound: this is intentional, and can be changed with C++. However, a non-looping sound can be stopped by using the Volume input with a value of 0.
Toggles a looping sound between playing and stopped. Behaves like PlaySound if the sound is unlooped.
Volume <float>
Plays the sound at a volume from 0 to 10, where 10 is the loudest.
Bug.png 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.
Bug.png Bug: Setting the volume to 0 will cause the sound to pause, rather than play silently.
FadeIn <int>
Fades the sound up to full volume over a specified number of seconds, with a range from 0 to 100 seconds.
Bug.png Bug: Non-functional.
FadeOut <int>
Fades the sound to silence over a specified number of seconds, with a range from 0 to 100 seconds.
Bug.png Bug: Will bring the sound up to full volume (i.e. 10) before beginning to fade it.


AddContext <string>
Adds to the entity's list of response contexts. Format is <key>:<value>.
AddOutput <string>
Assigns a new keyvalue/output on this entity. For keyvalues, some rely on extra necessary code to be ran and won't work if its simply just changed through this input. There is a strict format that must be followed:

Removes all contexts from this entity's list.
Removes this entity from the the movement hierarchy, leaving it free to move independently.
FireUser1 to FireUser4
Fires the respectiveOnUseroutputs; see User Inputs and Outputs.
Removes this entity and any entities parented to it from the world.
Functions the same as Kill, although this entity and any entities parented to it are killed on the same frame, being marginally faster thanKillinput.
RemoveContext <string>
Remove a context from this entity's list. The name should match the key of an existing context.
SetParent <string>
Move with this entity. See Entity Hierarchy (parenting).
SetParentAttachment <string>
Change this entity to attach to a specific attachment point on its parent. The entity will teleport so that the position of its root bone matches that of the attachment. Entities must be parented before being sent this input.
SetParentAttachmentMaintainOffset <string>
As above, but without teleporting. The entity retains its position relative to the attachment at the time of the input being received.
Use  !FGD
Same as a player invoking +use; no effect in most cases.
DispatchResponse <string> !FGD
Dispatches a response to the entity. See Response and Concept.
DispatchEffect <string> (removed since Left 4 Dead) !FGD
Dispatches a special effect from the entity's origin; see also List of Client Effects. Replaced by the particle system since Left 4 Dead.
RunScriptFile <script> (in all games since Left 4 Dead 2)
Execute a VScript file from disk, without file extension. The script contents are merged with the script scope of the receiving entity.
RunScriptCode <string> (in all games since Left 4 Dead 2)
Execute a string of VScript source code in the scope of the entity receiving the input. String quotation may be needed when fired via console.
Bug.png Bug: In Hammer, using string arguments will corrupt the VMF file's structure, making the file unviewable for the next Hammer session.
Fix: Remove the string argument manually with a text editor.
CallScriptFunction <string> (in all games since Left 4 Dead 2) !FGD
Execute a VScript function in the scope of the receiving entity.
SetLocalOrigin <coordinates> (in all games since Alien Swarm) !FGD
Send this entity to a spot in the map. If the entity is parented to something, it will be offset from the parent by this amount.
SetLocalAngles <angles> (in all games since Alien Swarm) !FGD
Set this entity's angles.



OnUser1 to OnUser4
These outputs each fire in response to the firing of the like-numbered FireUser1 to FireUser4 Input; see User Inputs and Outputs.
OnKilled  (only in Left 4 Dead Left 4 Dead 2)
This output fires when the entity is killed and removed from the game.

See also