Sound
The Sound class provides a high-level interface for playing and controlling both 2D and 3D audio in-game.
It allows you to spawn sounds at specific locations, adjust playback properties such as volume, pitch, and attenuation, and apply effects like fading, filtering, and modulation.
The class also exposes functions for querying playback state, retrieving audio analysis data (such as FFT and envelope data), and customizing audio routing and parameters.
Constructorโ
local SoundActor = Sound(
Vector(-7940, 7402, 150),
'/Engine/VREditor/Sounds/UI/Enter_Play',
false,
false,
1.0,
1.0,
400,
600,
AttenuationFunction.Linear,
true
)
print(SoundActor.Object) -- AActor
print(SoundActor.Component) -- UAudioComponent
| Type | Name | Default | Description |
|---|---|---|---|
| Vector | Location | The location to spawn the decal at. | |
| string | SoundAsset | The path to a USoundBase asset. | |
| boolean? | bIs2D | true | Whether the sound is to be 2D sound, or a 3D sound. |
| boolean | bAutoDestroy | Whether to automatically destroy the component once the sound has finished playing. | |
| number | Volume | The volume multiplier the sound will play at. | |
| number | Pitch | The pitch multiplier applied to the sound. | |
| number | Radius | The inner radius for sound attenuation. | |
| number | FalloffDistance | The falloff distance for sound attenuation. | |
| AttenuationFunction NOTE: Needs Enum | AttenuationFunction | The attenuation function enum to use for sound attenuation. |
Functionsโ
Playโ
Starts playing the targeted audio componentโs sound.
- startTime:
number- Time offset (in seconds) to begin playback from
SoundActor:Play(30)
Stopโ
Stops the audio componentโs sound immediately and issues any relevant delegates.
SoundActor:Stop()
StopDelayedโ
Cues a stop request after a given delay (in seconds). Stops immediately if DelayTime <= 0.
- delayTime:
number- Delay before stopping the sound
SoundActor:StopDelayed(delayTime)
FadeInโ
Fades the sound in over a duration with optional volume curve
- FadeInDuration:
numberโ Duration of the fade-in. - FadeVolumeLevel:
number(default: 1.0) โ Target volume level. - StartTime:
number(default: 0) โ Optional start time offset in seconds. - FadeCurve:
EAudioFaderCurve(default: Linear) โ Curve shape used for fading.
SoundActor:FadeIn(FadeInDuration, FadeVolumeLevel, StartTime, FadeCurve)
FadeOutโ
Fades the sound out over a duration with optional volume curve
- FadeOutDuration:
number- duration of fade-out - FadeVolumeLevel:
number- final volume level (default:0) - FadeCurve:
EAudioFaderCurveโ curve shape used for fading
SoundActor:FadeOut(FadeOutDuration, FadeVolumeLevel, FadeCurve)
SetPausedโ
Pauses or resumes the audio componentโs playback
- bPause:
boolean
SoundActor:SetPaused(bPause)
SetVolumeMultiplierโ
Sets a new global volume multiplier for the sound
- NewVolumeMultiplier:
number
SoundActor:SetVolumeMultiplier(NewVolumeMultiplier)
SetPitchMultiplierโ
Sets a new pitch multiplier for the sound
- NewPitchMultiplier:
number- Multiplier for playback pitch (e.g., 1.0 is normal pitch)
SoundActor:SetPitchMultiplier(NewPitchMultiplier)
SetUISoundโ
Marks the sound as UI sound (used for mixing purposes)
- bInUISound:
boolean- Whether this sound should be treated as a UI sound
SoundActor:SetUISound(bInUISound)
SetSoundโ
Changes the sound asset being played by the component
- NewSound: USoundBase
SoundActor:SetSound(NewSound)
SetLowPassFilterEnabledโ
Enables/disables a low-pass filter for this sound
- InLowPassFilterEnabled:
boolean- Whether the LPF is enabled
SoundActor:SetLowPassFilterEnabled(InLowPassFilterEnabled)
SetLowPassFilterFrequencyโ
Sets the cutoff frequency (Hz) for the low-pass filter
- InLowPassFilterFrequency:
number- Frequency threshold for LPF (in Hz)
SoundActor:SetLowPassFilterFrequency(InLowPassFilterFrequency)
SetHighPassFilterEnabledโ
Enables/disables a high-pass filter for this sound
- InHighPassFilterEnabled:
boolean- Whether the HPF is enabled
SoundActor:SetHighPassFilterEnabled(InHighPassFilterEnabled)
SetHighPassFilterFrequencyโ
Sets the cutoff frequency (Hz) for the high-pass filter
- InHighPassFilterFrequency:
number- Frequency threshold for HPF (in Hz)
SoundActor:SetHighPassFilterFrequency(InHighPassFilterFrequency)
SetSubmixSendโ
Sets the send level to a specific submix
- Submix: USoundSubmixBase
- SendLevel:
number- Volume level of the send
SoundActor:SetSubmixSend(Submix, SendLevel)
SetAudioBusSendPreEffectโ
Sets how much audio is sent to an Audio Bus before source effects
- AudioBus: UAudioBus - Audio bus to send to pre-effects
- AudioBusSendLevel:
number- Volume level of the send
SoundActor:SetAudioBusSendPreEffect(AudioBus, AudioBusSendLevel)
SetAudioBusSendPostEffectโ
Sets how much audio is sent to an Audio Bus after source effects
- AudioBus: UAudioBus - Audio bus to send to pre-effects
- AudioBusSendLevel:
number- Volume level of the send
SoundActor:SetAudioBusSendPostEffect(AudioBus, AudioBusSendLevel)
SetSourceBusSendPreEffectโ
Sets the send level to a Source Bus before effect processing
- SoundSourceBus: USoundSourceBus - Source bus to send to pre-effects
- SourceBusSendLevel:
number- Volume level of the send
SoundActor:SetSourceBusSendPreEffect(SoundSourceBus, SourceBusSendLevel)
SetSourceBusSendPostEffectโ
Sets the send level to a Source Bus after effect processing
- SoundSourceBus: USoundSourceBus - Source bus to send to pre-effects
- SourceBusSendLevel:
number- Volume level of the send
SoundActor:SetSourceBusSendPostEffect(SoundSourceBus, SourceBusSendLevel)
AdjustVolumeโ
Adjusts the playback volume smoothly over time using a curve
- AdjustVolumeDuration:
number- Time to reach the target volume - AdjustVolumeLevel:
number- Target volume level - FadeCurve: EAudioFaderCurve - Curve used for adjustment
SoundActor:AdjustVolume(AdjustVolumeDuration, AdjustVolumeLevel, FadeCurve)
IsPlayingโ
Returns whether the sound is currently playing
- returns:
boolean
local bPlaying = SoundActor:IsPlaying()
IsVirtualizedโ
Returns whether the sound is virtualized (paused due to distance or other factors)
- returns:
boolean
local bVirtualized = SoundActor:IsVirtualized()
GetPlayStateโ
Returns the current play state of the audio component
- returns: EAudioComponentPlayState - Enum indicating current playback state
local playState = SoundActor:GetPlayState()
HasCookedFFTDataโ
Checks if the current sound has precomputed FFT data available
- returns:
boolean
local hCookedF = SoundActor:HasCookedFFTData()
HasCookedAmplitudeEnvelopeDataโ
Checks if the current sound has amplitude envelope data
- returns:
boolean
local hCookedA = SoundActor:HasCookedAmplitudeEnvelopeData()
GetCookedEnvelopeDataForAllPlayingSoundsโ
Gets the current-time amplitude envelope data of the sounds playing on the audio component. Envelope data is not averaged or interpolated. Instead an array of data with all playing sound waves with cooked data is returned.
- returns:
boolean | TArray
local OutEnvelopeData = UE.TArray()
local DataFound = SoundActor:GetCookedEnvelopeDataForAllPlayingSounds(OutEnvelopeData)
OR
local DataFound, OutEnvelopeData = SoundActor:GetCookedEnvelopeDataForAllPlayingSounds(OutEnvelopeData)
GetCookedEnvelopeDataโ
Gets the current amplitude envelope value of the sound
- OutEnvelopeData:
number- Output variable for the current envelope value - returns:
boolean
local gCookedE = SoundActor:GetCookedEnvelopeData(OutEnvelopeData)
GetCookedFFTDataForAllPlayingSoundsโ
Gets the current-time cooked spectral data of the sounds playing on the audio component. Spectral data is not averaged or interpolated. Instead an array of data with all playing sound waves with cooked data is returned.
- returns:
boolean | TArray
local OutSoundWaveSpectralData = UE.TArray()
local DataFound = SoundActor:GetCookedFFTDataForAllPlayingSounds(OutEnvelopeData)
OR
local DataFound, OutEnvelopeData = SoundActor:GetCookedFFTDataForAllPlayingSounds(OutEnvelopeData)
GetCookedFFTDataโ
Gets the spectral FFT data for specified frequencies
- FrequenciesToGet:
TArray- List of frequencies to retrieve data for - OutSoundWaveSpectralData:
TArray- Output array for spectral data - returns:
boolean
SoundActor:GetCookedFFTData(FrequenciesToGet, OutSoundWaveSpectralData)
SetIntParameterโ
Sets a named integer parameter on the sound
- InName:
string- Name of the parameter - InInt:
integer- Value to set
SoundActor:SetIntParameter(InName, InInt)
SetFloatParameterโ
Sets a named float parameter on the sound
- InName:
string- Name of the parameter - InFloat:
number- Value to set
SoundActor:SetFloatParameter(InName, InFloat)
SetBoolParameterโ
Sets a named boolean parameter on the sound
- InName:
string- Name of the parameter - InBool:
boolean- Value to set
SoundActor:SetBoolParameter(InName, InBool)
SetWaveParameterโ
Sets a named wave parameter on the sound
- InName: string - Name of the parameter
- InWave: USoundWave - Wave to assign
SoundActor:SetWaveParameter(InName, InWave)
SetAttenuationSettingsโ
Sets the attenuation settings for the sound
- InAttenuationSettings: USoundAttenuation - The sound attenuation instance used to be set
SoundActor:SetAttenuationSettings(InAttenuationSettings)
SetAttenuationOverridesโ
Sets the attenuation settings for the sound by overriding
- InAttenuationSettings: FSoundAttenuationSettings - The sound attenuation structure used to override the attenuation settings
SoundActor:SetAttenuationOverrides(InAttenuationSettings)
AdjustAttenuationโ
Modifies the attenuation settings on the component
- InAttenuationSettings: FSoundAttenuationSettings - Updated settings to apply
SoundActor:AdjustAttenuation(InAttenuationSettings)
BP_GetAttenuationSettingsToApplyโ
Retrieves the current attenuation settings applied to the sound
- OutAttenuationSettings: FSoundAttenuationSettings - Output structure to receive settings
- returns:
boolean
local success = SoundActor:BP_GetAttenuationSettingsToApply(OutAttenuationSettings)
SetOutputToBusOnlyโ
Controls whether the audio is output only to the bus
- bInOutputToBusOnly:
boolean- Whether to route output only to the bus
SoundActor:SetOutputToBusOnly(bInOutputToBusOnly)
SetOverrideAttenuationโ
Overrides the default attenuation behavior
- bInOverrideAttenuation:
boolean- Whether to override attenuation settings
SoundActor:SetOverrideAttenuation(bInOverrideAttenuation)
SetModulationRoutingโ
Sets modulation routing for a destination
- Modulators: USoundModulatorBase - Modulators to use
- Destination: EModulationDestination - Where to apply modulation
- RoutingMethod: EModulationRouting - Method of routing modulators
SoundActor:SetModulationRouting(Modulators, Destination, RoutingMethod)
AddModulationRoutingโ
Adds modulators to existing modulation routing
- Modulators: USoundModulatorBase - Modulators to add
- Destination: EModulationDestination - Where to apply added modulators
SoundActor:AddModulationRouting(Modulators, Destination)
RemoveModulationRoutingโ
Removes modulators from existing routing
- Modulators: USoundModulatorBase - Modulators to remove
- Destination: EModulationDestination - Where to remove modulators from
SoundActor:RemoveModulationRouting(Modulators, Destination)
GetModulatorsโ
Gets active modulators for a given modulation destination
- Destination: EModulationDestination - Which destination to query
- returns:
TSetUSoundModulatorBase
SoundActor:GetModulators(Destination)
PlayQuantizedโ
Plays the sound aligned to a quantization boundary using a clock handle
- WorldContextObject: UObject - Context object, for example the world.
- InClockHandle: UQuartzClockHandle - Handle to the clock.
- InQuantizationBoundary: FQuartzQuantizationBoundary - Quantization boundary.
- InDelegate: Delegate - Delegate to call on completion.
- InStartTime: number (default:
0) - Optional start time. - InFadeInDuration: number (default:
0) - Fade-in duration. - InFadeVolumeLevel: number (default:
1.0) - Target volume. - InFadeCurve: EAudioFaderCurve (default:
Linear) - Fade curve.
SoundActor:PlayQuantized(WorldContextObject, InClockHandle, InQuantizationBoundary, InDelegate, InStartTime, InFadeInDuration, InFadeVolumeLevel, InFadeCurve)