Skip to content

Services

Valk edited this page Oct 4, 2024 · 19 revisions

Important

The service attribute is only valid on scripts that extend from Node.

Example 1

[Service] // This service will get cleaned up on scene change
public partial class Vignette : ColorRect
{
    public void LightPulse() { ... }
}
Vignette vignette = Services.Get<Vignette>();
vignette.LightPulse();

Example 2

[Service(ServiceLifeTime.Application)] // This service will stay alive forever
public partial class AudioManager : Node
{
    public void PlayMusic(AudioStream song) {...}
}
AudioManager audioManager = Services.Get<AudioManager>();
audioManager.PlayMusic(menuTheme);
Clone this wiki locally