MusicComponentclass

Plays background music through `Sandbox.Game.Music`. Drop it in, pick a track. Only one track plays at a time, so enabling another music component crossfades to it. Music isn't tied to the scene - to keep a track going across scene loads either put this on a DontDestroyOnLoad object or turn off StopOnDisable.

objectComponentMusicComponent
Namespace
Sandbox
Assembly
Sandbox.Engine
Declaration
public sealed class Sandbox.MusicComponent : Sandbox.Component

Constructors1

Showing 1 constructors

Methods2

Showing 2 methods

public void Play()PUBLIC

Play this track, crossfading from whatever is playing.

Returns:void

public void Stop()PUBLIC

Fade out and stop, if this track is the one playing.

Returns:void

Properties7

Showing 7 properties

public float Sandbox.MusicComponent.FadeIn { get; set; }PUBLICGETSET

Seconds to fade in when starting, and to crossfade from whatever was playing.

Returns:float

public float Sandbox.MusicComponent.FadeOut { get; set; }PUBLICGETSET

Seconds to fade out when stopping.

Returns:float

public bool Sandbox.MusicComponent.Loop { get; set; }PUBLICGETSET

Start again when the track ends.

Returns:bool

public bool Sandbox.MusicComponent.PlayOnStart { get; set; }PUBLICGETSET

Start playing as soon as this component is enabled.

Returns:bool

public bool Sandbox.MusicComponent.StopOnDisable { get; set; }PUBLICGETSET

Stop the music when this component is disabled or destroyed, if it's still the track playing. Turn off to let it carry on, e.g. across a scene load.

Returns:bool

public Sandbox.SoundFile Sandbox.MusicComponent.Track { get; set; }PUBLICGETSET

The music to play. Tick Loop in the sound editor for a gapless loop.

Returns:SoundFile

public float Sandbox.MusicComponent.Volume { get; set; }PUBLICGETSET

Volume of this track, on top of the game's music volume.

Returns:float

On this page