TExcelTAD
Home › Godot 4 with GDScript › Project Settings & Autoloads

Project Settings & Autoloads

Two project-wide tools come up in every game: Project Settings, which configure the window, physics, input and rendering, and autoloads, nodes that live for the whole run of the game and outlast scene changes. This lesson covers both, along with the main scene and changing scenes.

Project Settings

Open Project > Project Settings. The General tab is a searchable list of hundreds of settings grouped by category; switch on Advanced Settings (top right) to see all of them. Other tabs hold the Input Map, Localization, Globals (autoloads and global groups) and Plugins.

Settings you change in the first hour of most projects:

Setting Path Why
Main scene application/run/main_scene the scene F5 and exported games start with
Viewport size display/window/size/viewport_width / _height the game's base resolution (default 1152 x 648)
Stretch mode display/window/stretch/mode canvas_items for most 2D games, viewport for pixel-perfect pixel art
Texture filter rendering/textures/canvas_textures/default_texture_filter Nearest for crisp pixel art
Physics tick rate physics/common/physics_ticks_per_second 60 by default
2D gravity physics/2d/default_gravity 980 px/s² by default

Everything you change is written to project.godot (only non-default values):

ini
config_version=5

[application]

config/name="Coin Climber"
run/main_scene="res://main.tscn"
config/features=PackedStringArray("4.7", "Forward Plus")

[autoload]

GameState="*res://autoload/game_state.gd"

[display]

window/size/viewport_width=640
window/size/viewport_height=360
window/stretch/mode="canvas_items"

[rendering]

textures/canvas_textures/default_texture_filter=0

Code reads the same settings through the ProjectSettings singleton. Run against a fresh project, you see the defaults:

gdscript · try it yourself
extends SceneTree

func _init():
	for key in ["display/window/size/viewport_width", "display/window/size/viewport_height",
			"physics/common/physics_ticks_per_second", "physics/2d/default_gravity",
			"display/window/stretch/mode", "rendering/renderer/rendering_method"]:
		print(key, " = ", ProjectSettings.get_setting(key))
	# A setting that doesn't exist: get_setting() returns the fallback value.
	print("game/difficulty = ", ProjectSettings.get_setting("game/difficulty", "normal"))
	print("Engine.physics_ticks_per_second = ", Engine.physics_ticks_per_second)
	quit()
display/window/size/viewport_width = 1152
display/window/size/viewport_height = 648
physics/common/physics_ticks_per_second = 60
physics/2d/default_gravity = 980.0
display/window/stretch/mode = disabled
rendering/renderer/rendering_method = forward_plus
game/difficulty = normal
Engine.physics_ticks_per_second = 60

Note: Changing a ProjectSettings value at runtime does not reconfigure the engine; most settings are read once at startup. To change things live, use the runtime APIs: Engine.physics_ticks_per_second, Engine.max_fps, DisplayServer.window_set_mode(), get_window().content_scale_factor. Player options (volume, key bindings) belong in a ConfigFile in user://, not in project settings.

You can add your own settings (type a name such as game/start_lives in the General tab's search bar and click Add) and override a setting per platform with feature tags: an entry like display/window/size/viewport_width.mobile applies only on mobile.

Changing scenes

The SceneTree holds one current scene. To switch levels:

gdscript
get_tree().change_scene_to_file("res://levels/level_02.tscn")
# or, with a scene you already loaded:
get_tree().change_scene_to_packed(next_level)
# or start over:
get_tree().reload_current_scene()

Godot removes and frees the old scene, then adds the new one. Everything inside the old scene is gone, including the score you kept in a variable there. Data that must survive a scene change lives in an autoload (or in a save file).

Autoloads

An autoload is a scene or script that Godot instances once at startup and adds directly under /root, before the main scene. It stays until the game quits. With Global Variable enabled (the * in project.godot), its name is usable everywhere as a global, so GameState.coins += 1 works from any script.

  1. Write the script, for example res://autoload/game_state.gd:

    gdscript
    extends Node
    
    signal coins_changed(total: int)
    
    var coins := 0
    
    func add_coins(n: int) -> void:
        coins += n
        coins_changed.emit(coins)
  2. Open Project > Project Settings > Globals > Autoload (older 4.x versions name the tab Autoload).

  3. Pick the script with the folder button, keep the Node Name GameState, keep Global Variable enabled, and click Add.

  4. In any scene: GameState.add_coins(1) or GameState.coins_changed.connect(_on_coins_changed).

The running tree then looks like this:

text
root (Window)
├── GameState        # autoload, survives scene changes
└── Level1           # current scene, replaced by change_scene_to_file()

The runnable model below adds a GameState node under /root the way Godot adds an autoload, then swaps two levels. Each level finds the autoload by its absolute path, /root/GameState, which is exactly what the global name resolves to:

gdscript · try it yourself
extends Node

# frames: 3

# GameState plays the role of an autoload named "GameState".
class GameState extends Node:
	signal coins_changed(total: int)
	var coins := 0

	func add_coins(n: int) -> void:
		coins += n
		coins_changed.emit(coins)

class Level extends Node:
	func _ready():
		var game := get_node("/root/GameState") as GameState
		game.coins_changed.connect(_on_coins_changed)
		print(name, " starts with ", game.coins, " coins")
		game.add_coins(5)

	func _on_coins_changed(total: int) -> void:
		print("  ", name, " HUD: ", total)

var level_number := 0
var current: Node

func _ready():
	var game := GameState.new()
	game.name = "GameState"
	get_tree().root.add_child.call_deferred(game)

func _process(_delta):
	if current:
		current.queue_free()   # roughly what changing the scene does to the old one
	level_number += 1
	if level_number <= 2:
		current = Level.new()
		current.name = "Level%d" % level_number
		add_child(current)
	else:
		print("game over with ", get_node("/root/GameState").coins, " coins")
Level1 starts with 0 coins
  Level1 HUD: 5
Level2 starts with 5 coins
  Level1 HUD: 10
  Level2 HUD: 10
game over with 10 coins

The coins survive both level changes. Look at the fourth line, though: Level1's HUD reacted although Level1 was already queued for deletion. queue_free() waits until the end of the frame, and until then the old level is still connected to the autoload's signal. When the node is freed, Godot disconnects it automatically, but anything that happens in between reaches it. This is a classic autoload bug ("the old level's handler ran once more"). Defend against it by keeping handlers harmless, or by disconnecting in _exit_tree().

Autoload discipline

Autoloads are convenient, and that is the danger: every script can reach them, so they become a global junk drawer. Rules that keep them healthy:

  • Few of them, each with one job: GameState (run data), Audio (music and SFX), SceneLoader (transitions), Settings. Not one per feature.
  • Data and signals, not scene logic. An autoload must not call into a specific level's nodes; levels come and go.
  • No order assumptions. Autoloads are added in the order of the list; one may use another in _ready only if it comes later in the list.
  • Things that belong to one scene (the player's HP, the current wave) stay in that scene.
  • For values that never change, a class_name script with const or static members needs no autoload at all (Classes).

Test yourself

Where in the tree does Godot put an autoload?

  1. Inside the main scene
  2. Directly under /root, before the main scene
  3. In user://
  4. Nowhere: autoloads are not nodes

You call ProjectSettings.set_setting("physics/common/physics_ticks_per_second", 120) at runtime. What happens?

  1. Physics ticks at 120 Hz immediately
  2. Nothing changes in the running game: most settings are read at startup; use Engine.physics_ticks_per_second
  3. The project file is deleted
  4. Godot crashes

Why did Level1's HUD print 10 in the example?

  1. Autoloads copy every handler
  2. queue_free() deletes at the end of the frame, so Level1 was still connected when Level2 added coins
  3. Level1 was never freed
  4. Signals are emitted twice