tModLoader v2025.06
A mod to make and play Terraria mods
SoundStyle Struct Reference

This data type describes in detail how a sound should be played.
Passable to the SoundEngine.PlaySound(in SoundStyle, Vector2?, SoundUpdateCallback?) method. More...

Public Member Functions

 SoundStyle (string soundPath, int numVariants, SoundType type=SoundType.Sound)
 
 SoundStyle (string soundPath, int variantSuffixesStart, int numVariants, SoundType type=SoundType.Sound)
 
 SoundStyle (string soundPath, ReadOnlySpan< int > variants, SoundType type=SoundType.Sound)
 
 SoundStyle (string soundPath, ReadOnlySpan<(int variant, float weight)> weightedVariants, SoundType type=SoundType.Sound)
 
 SoundStyle (string soundPath, SoundType type=SoundType.Sound)
 
float GetRandomPitch ()
 
SoundEffect GetRandomSound ()
 
SoundEffect GetSoundEffect ()
 
bool IsTheSameAs (SoundStyle style)
 Checks if this SoundStyle is the same as another SoundStyle. This method takes into account differences in chosen variants if LimitsArePerVariant is true.
 
bool IsVariantOf (SoundStyle style)
 Same as IsTheSameAs(SoundStyle) except it doesn't take into account differences in chosen variants.
 
SoundStyle WithPitchOffset (float offset)
 
SoundStyle WithVolumeScale (float scale)
 

Public Attributes

float minPitch
 A helper property for controlling both Pitch and PitchVariance at once. In XNA and FNA, Pitch ranges from -1.0f (down one octave) to 1.0f (up one octave). 0.0f is unity (normal) pitch.
 

Properties

string? Identifier = null [get, set]
 If defined, this string will be the only thing used to determine which styles should instances be shared with.
 
bool IsLooped = false [get, set]
 Whether or not to loop played sounds.
 
bool LimitsArePerVariant = false [get, set]
 If true, then variants are treated as different sounds for the purposes of SoundLimitBehavior and MaxInstances. Defaults to false, meaning that all variants share the same sound instance limitations.
 
int MaxInstances = 1 [get, set]
 The max amount of sound instances that this style will allow creating, before stopping a playing sound or refusing to play a new one.

If using variants, use LimitsArePerVariant to allow MaxInstances to apply to each variant individually rather than to all variants as a group.

Set to 0 for no limits.
 
PauseBehavior PauseBehavior = PauseBehavior.KeepPlaying [get, set]
 Determines how the sound will be affected when the game is paused (or unfocused) and subsequently resumed. Long-running sounds might benefit from changing this value.

Defaults to PauseBehavior.KeepPlaying, which means the sound will continue playing while the game is paused.
 
float Pitch [get, set]
 The pitch offset to play sounds with. In XNA and FNA, Pitch ranges from -1.0f (down one octave) to 1.0f (up one octave). 0.0f is unity (normal) pitch.
 
float float maxPitch PitchRange [get, set]
 
float PitchVariance [get, set]
 The pitch offset randomness value. Cannot be negative.
With Pitch at 0.0, and PitchVariance at 1.0, used pitch will range from -0.5 to 0.5. In XNA and FNA, Pitch ranges from -1.0f (down one octave) to 1.0f (up one octave). 0.0f is unity (normal) pitch.
 
bool PlayOnlyIfFocused = false [get, set]
 If true, this sound won't play if the game's window isn't selected.
 
int RerollAttempts [get, set]
 How many additional times to attempt to find a variant that is not currently playing before applying the SoundLimitBehavior. Only has effect if LimitsArePerVariant is true. Defaults to 0.
 
SoundLimitBehavior SoundLimitBehavior = SoundLimitBehavior.ReplaceOldest [get, set]
 Determines what the action taken when the max amount of sound instances is reached.

Defaults to SoundLimitBehavior.ReplaceOldest, which means a currently playing sound will be stopped and a new sound instance will be started.
 
string SoundPath [get, set]
 The sound effect to play.
 
SoundType Type [get, set]
 Controls which volume setting will this be affected by.
Ambience sounds also don't play when the game is out of focus.
 
ReadOnlySpan< int > Variants [get, set]
 An array of possible suffixes to randomly append to after SoundPath.
Setting this property resets VariantsWeights.
 
ReadOnlySpan< float > VariantsWeights [get, set]
 An array of randomization weights to optionally go with Variants.
Set this last, if at all, as the Variants's setter resets all weights data.
 
float Volume [get, set]
 The volume multiplier to play sounds with.
 

Detailed Description

This data type describes in detail how a sound should be played.
Passable to the SoundEngine.PlaySound(in SoundStyle, Vector2?, SoundUpdateCallback?) method.