← Pixel Dreamer Studio

A screen fade that finishes while the game is paused or slowed

Tell the tween to keep running while paused, and to count real seconds.

A tween stops while get_tree().paused is true, unless its node keeps processing, and it runs slower when Engine.time_scale is below 1. In our Godot 4.7 test a 0.5 s fade on a black overlay was still at 0.0 after one real second with the game paused, from the overlay's own tween and from get_tree().create_tween() alike. Setting the overlay to Process Mode Always fixed the pause but not slow motion: at time_scale 0.1 it reached only 0.2. A tween with set_pause_mode(Tween.TWEEN_PAUSE_PROCESS) and set_ignore_time_scale(true) reached 1.0 in both cases.

The code

Save it as ui_fade.gd, load it with const UiFade := preload("res://ui_fade.gd") and fade with UiFade.to(overlay, 1.0, 0.5), where the overlay is any CanvasItem, such as a ColorRect over the screen. To wait for it: await UiFade.to(overlay, 0.0, 0.5).finished. Use it for pause menus, scene transitions and game over screens, and keep normal tweens for things that should stop with the game.

extends RefCounted
## Fades a screen overlay (a transition, a pause menu, a "Game Over" screen)
## so it keeps going while the game is paused or slowed down.
## A normal tween stops while get_tree().paused is true and slows down with
## Engine.time_scale, so a fade started at those moments freezes or crawls.
##   UiFade.to(overlay, 1.0, 0.5)                       # fade in over 0.5 real seconds
##   await UiFade.to(overlay, 0.0, 0.5).finished          # fade out, then carry on


static func to(node: CanvasItem, alpha: float, seconds: float) -> Tween:
	var t := node.create_tween()
	t.set_pause_mode(Tween.TWEEN_PAUSE_PROCESS)  # runs while the tree is paused
	t.set_ignore_time_scale(true)                # real seconds, whatever Engine.time_scale is
	t.tween_property(node, "modulate:a", alpha, seconds)
	return t

What we measured

A black ColorRect on a CanvasLayer, faded from 0 to 1 over 0.5 s, then read after one real second, timed with a timer that runs while paused and ignores time_scale. Two runs gave the same values.

Why it happens

A tween made with create_tween() on a node follows that node: when the node would stop processing because the tree is paused, the tween stops too. A tween from get_tree().create_tween() stopped as well in our test. Process Mode Always keeps the node, and so its tweens, running, but tweens still count game time, and Engine.time_scale shrinks game time, which is what a hit stop or slow motion uses. TWEEN_PAUSE_PROCESS lets the tween run while paused whatever its node does, and set_ignore_time_scale(true) makes it count real seconds.

What to change

Transitions with more style than a black fade: PD Ink Wash has 12 ink looks for 3D, 2D full-screen and sprite shaders, and 8 ink brush scene transitions that let clicks through to your buttons.

Tested in Godot 4.7 with the Compatibility renderer.

Ready-made: PD Ink Wash has 12 ink looks for 3D, 2D full-screen and sprite shaders, and 8 ink brush scene transitions that let clicks through to your buttons.

More how-tos for PD Ink Wash: Full-screen post-process shader in 3D

More how-tos: UI and HUD