Skip to main content
Version: bleeding-edge 🩸

πŸ”Š Sound

Class for playing in-game 2D and 3D sounds.

This class can only be spawned on 🟧 Client.
This class inherits from Base Actor .

You can also load raw .ogg files from disk! Please check SpecialPath.

πŸŽ’ Examples​

local my_sound = Sound(
Vector(-510, 145, 63), -- Location (if a 3D sound)
"nanos-world::A_VR_Confirm", -- Asset Path
false, -- Is 2D Sound
true, -- Auto Destroy (if to destroy after finished playing)
1, -- Volume
1 -- Pitch
-- Spawning a ogg sound located in a Package
local ogg_sound = Sound(Vector(), "package://my-package/Client/awesome_beep.ogg", true)

πŸ—οΈ Constructor​

local my_sound = Sound(location, asset, is_2D_sound?, auto_destroy?, sound_type?, volume?, pitch?, inner_radius?, falloff_distance?, attenuation_function?, keep_playig_when_silent?, loop_mode?)
Vector locationOnly used if 3D sound
Sound Reference assetThe Sound Asset to load
boolean is_2D_soundfalseWhether to spawn it as 2D or 3D
boolean auto_destroytrueWhether to destroy after finished playing
SoundTypesound_typeSoundType.SFXUsed to apply user's volume settings
number volume1
number pitch1
number inner_radius400Only used if 3D sound
number falloff_distance3600Only used if 3D sound
AttenuationFunctionattenuation_functionLinearOnly used if 3D sound
boolean keep_playig_when_silentfalseOnly used if 3D sound - Use with caution, it may cause performance issues!
SoundLoopModeloop_modeDefaultWhether should force sound to loop

auto_destroy means the Entity will be immediately destroyed after spawned, losing references to the Particle System spawned in-game. So if the Particle System itself loops indefinitely, it will keep playing until the Player reconnects.

🦠 Functions​

Inherited Actor Functions
Base Actorscripting-reference/classes/base-classes/actor
AddImpulseApplies a force in world world to this Actor
AttachToAttaches this Actor to any other Actor, optionally at a specific bone
DestroyDestroys this Actor
DetachDetaches this Actor from AttachedTo Actor
SetCollisionSets this Actor's collision type
SetDimensionSets this Actor's Dimension
SetForceAdds a permanent force to this Actor, set to Vector(0, 0, 0) to cancel
SetGravityEnabledSets whether gravity is enabled on this Actor
SetVisibilitySets whether the actor is visible or not
SetHighlightEnabledSets whether the highlight is enabled on this Actor, and which highlight index to use
SetOutlineEnabledSets whether the outline is enabled on this Actor, and which outline index to use
SetLifeSpanSets the time (in seconds) before this Actor is destroyed. After this time has passed, the actor will be automatically destroyed.
SetLocationSets this Actor's location in the game world
SetRotationSets this Actor's rotation in the game world
SetRelativeLocationSets this Actor's relative location in local space (only if this actor is attached)
SetRelativeRotationSets this Actor's relative rotation in local space (only if this actor is attached)
SetScaleSets this Actor's scale
SetNetworkAuthoritySets the Player to have network authority over this Actor
SetValueSets a value in this Actor
TranslateToSmoothly moves this actor to a location over a certain time
RotateToSmoothly rotates this actor to an angle over a certain time
boolean IsBeingDestroyedReturns true if this Actor is being destroyed
boolean IsVisibleReturns true if this Actor is visible
boolean IsGravityEnabledReturns true if gravity is enabled on this Actor
boolean IsInWaterReturns true if this Actor is in water
boolean IsNetworkDistributedReturns true if this Actor is currently network distributed
boolean IsValidReturns true if this Actor is valid (i.e. wasn't destroyed and points to a valid Actor)
table of Base Actor GetAttachedEntitiesGets all Actors attached to this Actor
Base Actor or nilGetAttachedToGets the Actor this Actor is attached to
table GetBoundsGets this Actor's bounds
CollisionTypeGetCollisionGets this Actor's collision type
number GetIDGets the universal network ID of this Actor (same on both client and server)
Vector GetLocationGets this Actor's location in the game world
Rotator GetRotationGets this Actor's angle in the game world
Vector GetForceGets this Actor's force (set by SetForce())
boolean HasNetworkAuthorityReturns true if the local Player is currently the Network Authority of this Actor
boolean HasAuthorityGets if this Actor was spawned by the client side
Vector GetScaleGets this Actor's scale
string GetTypeGets the type of this Actor
any GetValueGets a value stored on this Actor at the given key. Please refer to Entity Values for more information
Vector GetVelocityGets this Actor's current velocity
AddActorTagAdds an Unreal Actor Tag to this Actor
RemoveActorTagRemoves an Unreal Actor Tag from this Actor
table of string GetActorTagsGets all Unreal Actor Tags on this Actor
function SubscribeSubscribes to an Event
UnsubscribeUnsubscribes all callbacks from this Event in this Actor within this Package, or only the callback passed
FadeInPlays the sound with a fade effect
FadeOutStops the sound with a fade effect
PlayStarts the sound
SetFalloffDistanceIf a 3D Sound, sets the distance which the sound is inaudible
SetInnerRadiusIf a 3D Sound, sets the distance within the volume is 100%
SetLowPassFilterSets lowpass filter frequency. Sets 0 to disable it.
SetPausedPauses the sound
SetPitchSets the Sound's pitch
SetVolumeSets the Sound's volume
StopStops the sound
StopDelayedStops the sound after the provided delay
boolean Is2DGets if the sound is 2D
boolean IsPlayingGets if the sound is playing
number GetDurationGets the duration of the Sound
number GetPitch
number GetVolume
number GetLowPassFilter
number GetInnerRadius
number GetFalloffDistance
number GetSoundType


Plays the sound with a fade effect
my_sound:FadeIn(fade_in_duration, fade_volume_level?, start_time?)
number fade_in_duration
number fade_volume_level?1
number start_time?0


Stops the sound with a fade effect
my_sound:FadeOut(fade_out_duration, fade_volume_level?, destroy_after_fadeout?)
number fade_out_duration
number fade_volume_level?0
boolean destroy_after_fadeout?false


Starts the sound
number start_time?0


If a 3D Sound, sets the distance which the sound is inaudible
number falloff_distance


If a 3D Sound, sets the distance within the volume is 100%
number inner_radius


Sets lowpass filter frequency. Sets 0 to disable it.
number frequency


Pauses the sound
boolean pause?true


Sets the Sound's pitch
number new_pitch


Sets the Sound's volume
number new_volume0-1


Stops the sound


Stops the sound after the provided delay
number delay


Gets if the sound is 2D

Returns boolean ()
local ret = my_sound:Is2D()


Gets if the sound is playing

Returns boolean ()
local ret = my_sound:IsPlaying()


Gets the duration of the Sound

Returns number ()
local ret = my_sound:GetDuration()


Returns number ()
local ret = my_sound:GetPitch()


Returns number ()
local ret = my_sound:GetVolume()


Returns number ()
local ret = my_sound:GetLowPassFilter()


Returns number ()
local ret = my_sound:GetInnerRadius()


Returns number ()
local ret = my_sound:GetFalloffDistance()


Returns number ()
local ret = my_sound:GetSoundType()

πŸš€ Events​

Inherited Actor Events
Base Actorscripting-reference/classes/base-classes/actor
DestroyTriggered when an Actor is destroyed
SpawnTriggered when an Actor is spawned/created
ValueChangeTriggered when an Actor has a value changed with :SetValue()
This entity doesn't have own events.

πŸ”Š Sound Attenuation​

This property defines the function that determines the rate of attenuation over distance. There are a number of different functions to choose from:

πŸ”ˆ Linear​

This is the default function. When using this function the volume will attenuate linearly and so the changes in volume are constant as the listener moves towards and away from the source. This function is good for crossfading between large background-type sounds that don't need tightly focussed 3D spatial falloff settings.

πŸ”ˆ Logarithmic​

When using this function the volume attenuates such that the changes in volume are greater at close distances, and lesser at far distances. This function is good for spot sounds that need good 3D positioning, while still being audible at reasonable distances.

πŸ”ˆ Inverse​

When using this function, the changes in volume are similar to that of the logarithmic curve, but are more exaggerated. This function is good for sounds that only need to be just audible at far distances, but that gets significantly louder as the listener gets quite close to the source.

πŸ”ˆ Log Reverse​

When using this function, the changes in volume are lesser at close distances, with more dramatic differences at far distances. This function is good for sounds that need to be loud across larger distances.

πŸ”ˆ Natural Sound​

This function attempts to model a more 'naturalistic' falloff behavior to produce behaviors that closer match reality. This function is a kind of 'middle ground' between the Logarithmic and Inverse functions.