Passer au contenu principal
Version: latest - a1.7.0 ⚖️

🔊 Sound

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

info

🟧 Authority: This class can only be spawned on Client.

Inheritance: This class inherits from Actor.

tip

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

Utilisation

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)
SoundType.SFX,
1, -- Volume
1 -- Pitch
)

Constructor Parameters

TypeNomDefaultDescription
VectorlocationVector(0, 0, 0)3D only
Sound Asset or Special Pathasset``The Sound Asset or Special Path
booleanis_2D_soundfalse
booleanauto_destroytrueIf to destroy after finished playing
SoundTypesound_typeSoundType.SFXUsed to apply user's volume settings
numbervolume1
numberpitch1
numberinner_radius4003D only
numberfalloff_distance36003D only
AttenuationFunctionattenuation_functionLinear3D only
booleankeep_playing_when_silentfalse3D only - Whether to keep playing this sound when it's not audible - Use with caution, it may cause performance issues!
SoundLoopModeloop_modeDefaultLoop Mode (if should force sound to loop)

Functions

Inherited Actor Functions
ReturnsNameDescription
AddImpulseApplies a Force in world space to this Actor
AttachToAttaches this Actor to another Actor
DestroyDestroys this Actor
DetachDetaches this Actor if attached
SetCollisionSets this Actor's collision type
SetForceAdds a permanent force to this Actor
SetGravityEnabledSets whether gravity is enabled on this Actor
SetVisibilitySets the Actor visibility
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
SetLocationSets this Actor's location in the game world
SetNetworkAuthoritySets the Player this Actor will have its physics calculated on Network Authority
SetRelativeLocationSets this Actor's relative location in local space
SetRelativeRotationSets this Actor's relative rotation in local space
SetRotationSets this Actor's rotation in the game world
SetScaleSets this Actor's scale
SetValueSets a value in this Actor, which can be accessed by any package
TranslateToSmoothly moves this Actor to the specified location
RotateToSmoothly rotates this Actor to the specified angle
booleanHasNetworkAuthorityGets if the LocalPlayer is currently the Network Authority of this Actor
booleanHasAuthorityGets if this Actor was spawned by the client side
booleanIsBeingDestroyedGets if this Actor is being destroyed
booleanIsGravityEnabledGets whether gravity is enabled on this Actor
booleanIsVisibleGets whether this actor is Visible or not
booleanIsInWaterGets if this Actor is in water
booleanIsNetworkDistributedGets if this Actor is currently Network Distributed
booleanIsValidReturns if this Actor is valid (i.e. not destroyed)
tableGetAttachedEntitiesGets all Actors attached to this Actor
anyGetAttachedToGets the Actor this Actor is attached to
tableGetBoundsGets this Actor's bounds
numberGetCollisionGets this Actor's collision type
numberGetIDGets the universal network ID of this Actor
VectorGetLocationGets this Actor's location in the game world
RotatorGetRotationGets this Actor's angle in the game world
VectorGetForceGets this Actor's scale
VectorGetScaleGets this Actor's scale
stringGetTypeGets the type of this Actor
anyGetValueGets a value stored on this Actor at the given key
VectorGetVelocityReturns this Actor's current velocity
stringAddActorTagAdds an Unreal Actor Tag to this Actor
stringRemoveActorTag`Remove an Unreal Actor Tag from this Actor
tableGetActorTagsGets all Unreal Actor Tags from this Actor
functionSubscribeSubscribes to an Event
UnsubscribeUnsubscribes from an Event
Valeur retournéeNomDescription
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 (0 - 1)
StopStops the sound
StopDelayedStops the sound after the provided delay
booleanIs2DReturns if the sound is 2D
booleanIsPlayingReturns if the sound is playing
numberGetDurationReturns the duration of sound
numberGetPitchReturns the pitch
numberGetVolumeReturns the volume
numberGetLowPassFilterReturns the Low Pass Filter Frequency
numberGetInnerRadiusReturns the Attenuation Inner Radius
numberGetFalloffDistanceReturns the Attenuation Falloff Distance
SoundTypeGetSoundTypeReturns the Sound Type

Events

Inherited Actor Events
NameDescription
DestroyTriggered when an Actor is destroyed
SpawnTriggered when an Actor is spawned/created
ValueChangeTriggered when an Actor has a value changed with :SetValue()

FadeIn

Plays the sound with a fade effect

my_sound:FadeIn(fade_in_duration, fade_volume_level, start_time)
TypeParameterDefault ValueDescription
numberfade_in_duration
numberfade_volume_level1
numberstart_time0

FadeOut

Stops the sound with a fade effect

my_sound:FadeOut(fade_out_duration, fade_volume_level, destroy_after_fadeout)
TypeParameterDefault ValueDescription
numberfade_out_duration
numberfade_volume_level0
booleandestroy_after_fadeoutfalse

Play

Starts the sound

my_sound:Play(start_time)
TypeParameterDefault ValueDescription
numberstart_time0

SetFalloffDistance

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

my_sound:SetFalloffDistance(falloff_distance)
TypeParameterDescription
numberfalloff_distance

SetInnerRadius

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

my_sound:SetInnerRadius(inner_radius)
TypeParameterDescription
numberinner_radius

SetLowPassFilter

Sets lowpass filter frequency. Sets 0 to disable it.

my_sound:SetLowPassFilter(frequency)
TypeParameterDescription
numberfrequency

SetPaused

Pauses the sound

my_sound:SetPaused(pause)
TypeParameterDefault ValueDescription
booleanpausetrue

SetPitch

Sets the Sound's pitch

my_sound:SetPitch(new_pitch)
TypeParameterDescription
numbernew_pitch

SetVolume

Sets the Sound's volume (0 - 1)

my_sound:SetVolume(new_volume)
TypeParameterDescription
numbernew_volume

Stop

Stops the sound

my_sound:Stop()

StopDelayed

Stops the sound after the provided delay

my_sound:StopDelayed(delay)
TypeParameterDescription
numberdelay

Is2D

Gets if the sound is 2D

Returns boolean

my_sound:Is2D()

IsPlaying

Gets if the sound is playing

Returns boolean

my_sound:IsPlaying()

GetDuration

Gets the duration of the Sound.

Returns number

my_sound:GetDuration()

GetPitch

Returns number

my_sound:GetPitch()

GetVolume

Returns number

my_sound:GetVolume()

GetLowPassFilter

Returns number

my_sound:GetLowPassFilter()

GetInnerRadius

Returns number

my_sound:GetInnerRadius()

GetFalloffDistance

Returns number

my_sound:GetFalloffDistance()

GetSoundType

Returns number

my_sound:GetSoundType()

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.