What does the Singleton option in the AutoLoad tab of Project Settings do?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By chanon
:warning: Old Version Published before Godot 3 was released.

I’m beginning to use AutoLoad for singletons and am wondering what does the Singleton “Enable” option actually do or enable?

:bust_in_silhouette: Reply From: vinod

If you add a singleton script like this:

extends Node

var score

func _ready():
	score = 0

func incrementScore():
	score += 1

You can then add this script as Singleton and name it as ScoreManager. Then in anywhere in your game you can call

ScoreManager.incrementScore()

To increment your score.

You can use this technique to switch between scenes, manage music with crossfade transitions between scenes, manage sfx etc…

Very convenient. Nice!

chanon | 2016-04-16 14:44