Skip to content
godot-modernize-ui logo

Godot UI Modernization

godot-modernize-ui

Modernize Godot 3.x UI to 4.x best practices with theme extraction, responsive layouts, hiDPI support, and RichTextLabel BBCode patterns

Asreonn/godot-superpowers0installs4stars

SKILL.md

Full skill instructions

Godot UI Modernization

Modernizes Godot 3.x UI scenes and scripts to Godot 4.x best practices.

When to Use

  • Migrating Godot 3.x projects to 4.x with UI scenes
  • UI doesn't scale properly on hiDPI displays
  • Hardcoded styles scattered across Control nodes
  • Manual positioning instead of responsive anchoring
  • RichTextLabel using deprecated BBCode tags
  • Creating reusable custom controls

Core Patterns

1. Theme Resource Extraction

Before (Godot 3.x):

# Hardcoded in each Control node
$Button.modulate = Color.red
$Button.get("custom_styles/​normal").bg_color = Color.blue
$Label.add_font_override("font", preload("res://fonts/​big.tres"))

After (Godot 4.x):

# Centralized in Theme resource
# Create: res://ui/​themes/​main_theme.tres
# Assign to root Control or project settings

Theme.tres structure:

Theme
├── Button/​styles/​normal (StyleBoxFlat)
├── Button/​colors/​font_color = Color(1, 1, 1, 1)
├── Button/​fonts/​font = preload("res://fonts/​button_font.tres")
├── Label/​fonts/​font = preload("res://fonts/​label_font.tres")
└── Panel/​styles/​panel (StyleBoxFlat)

2. Control Anchoring Standardization

Before:

# Manual positioning
$Panel.position = Vector2(100, 100)
$Panel.size = Vector2(400, 300)

After:

Control (root)
├── Layout Mode: Anchors
├── Anchor Left: 0.5, Anchor Top: 0.5
├── Anchor Right: 0.5, Anchor Bottom: 0.5
├── Grow Horizontal: Center
├── Grow Vertical: Center
└── Custom Minimum Size: (400, 300)

Anchor Presets for Common Layouts:

LayoutAnchorsOffsetsGrow
Fullscreen0,0 to 1,10 all sidesBoth
Top Bar0,0 to 1,0Bottom: 60Horizontal
Bottom Bar0,1 to 1,1Top: 60Horizontal
Center Panel0.5,0.5Size definedBoth
Left Sidebar0,0 to 0,1Right: 250Vertical
Right Sidebar1,0 to 1,1Left: 250Vertical

3. UI Scaling (hiDPI Support)

Project Settings:

Display > Window > Stretch
├── Mode: canvas_items (or viewport)
├── Aspect: expand
└── Scale: 1.0 (auto-detected)

Script for Dynamic Scaling:

func _ready():
    # Handle hiDPI on different displays
    var screen_dpi = DisplayServer.screen_get_dpi()
    if screen_dpi > 150:
        get_tree().root.content_scale_factor = 2.0

Responsive Sizing:

@export var base_width: float = 1920.0
@export var base_height: float = 1080.0

func _on_viewport_size_changed():
    var viewport_size = get_viewport().get_visible_rect().size
    var scale_x = viewport_size.x / base_width
    var scale_y = viewport_size.y / base_height
    scale = Vector2(min(scale_x, scale_y), min(scale_x, scale_y))

4. RichTextLabel BBCode Patterns

Deprecated Godot 3.x:

[color=red]Warning[/​color]
[url=https://example.com]Link[/​url]
[img]res://icon.png[/​img]

Godot 4.x BBCode:

[color=ff0000]Warning[/​color]
[color=#ff0000]Hex Color[/​color]
[url=https://example.com]Link[/​url]
[img=64x64]res://icon.png[/​img]
[font=res://fonts/​custom.tres]Custom font[/​font]
[wave amp=50 freq=5]Animated text[/​wave]
[tornado radius=5 freq=2]Spinning text[/​tornado]
[shake rate=5 level=10]Shaking text[/​shake]
[fgcolor=00ff00 bgcolor=000000]Background[/​fgcolor]
[outline_color=ffffff]Outlined[/​outline_color]

Script Integration:

@onready var rich_label: RichTextLabel = $RichTextLabel

func append_colored_text(text: String, color: Color):
    rich_label.append_text("[color=%s]%s[/​color]" % [color.to_html(), text])

func append_url(text: String, url: String):
    rich_label.append_text("[url=%s]%s[/​url]" % [url, text])
    
func _on_meta_clicked(meta):
    OS.shell_open(str(meta))

5. Custom Control Creation

Custom Button with Built-in Theme:

@tool
class_name ModernButton
extends Button

@export var button_style: ButtonStyle = ButtonStyle.PRIMARY:
    set(value):
        button_style = value
        _update_style()

enum ButtonStyle { PRIMARY, SECONDARY, DANGER }

func _ready():
    _update_style()

func _update_style():
    match button_style:
        ButtonStyle.PRIMARY:
            add_theme_color_override("font_color", Color(1, 1, 1))
            add_theme_stylebox_override("normal", preload("res://ui/​styles/​primary_normal.tres"))
        ButtonStyle.SECONDARY:
            add_theme_color_override("font_color", Color(0.2, 0.2, 0.2))
            add_theme_stylebox_override("normal", preload("res://ui/​styles/​secondary_normal.tres"))
        ButtonStyle.DANGER:
            add_theme_color_override("font_color", Color(1, 1, 1))
            add_theme_stylebox_override("normal", preload("res://ui/​styles/​danger_normal.tres"))

Responsive Design Patterns

Container Hierarchy

CanvasLayer (UI Layer)
└── Control (Full Rect anchor, Fullscreen preset)
    ├── MarginContainer (padding)
    │   ├── VBoxContainer (vertical layout)
    │   │   ├── HBoxContainer (top bar)
    │   │   │   ├── Label (title)
    │   │   │   └── Button (close)
    │   │   └── ScrollContainer (scrollable content)
    │   │       └── VBoxContainer
    │   │           └── (dynamic content)
    │   └── HBoxContainer (bottom bar)
    │       └── Button (action)
    └── Panel (overlay/​popup)

Safe Area Handling (Mobile)

func _ready():
    # Apply safe area insets for notched devices
    var safe_area = DisplayServer.get_display_safe_area()
    var window_size = DisplayServer.window_get_size()
    
    $MarginContainer.add_theme_constant_override("margin_left", safe_area.position.x)
    $MarginContainer.add_theme_constant_override("margin_top", safe_area.position.y)
    $MarginContainer.add_theme_constant_override("margin_right", 
        window_size.x - safe_area.end.x)
    $MarginContainer.add_theme_constant_override("margin_bottom", 
        window_size.y - safe_area.end.y)

Common Mistakes

Using RectPosition/​RectSize directly:

# ❌ Bad - breaks with different resolutions
$Control.rect_position = Vector2(100, 100)
$Control.rect_size = Vector2(200, 150)

# ✅ Good - use anchors and layout containers
# Set anchors in editor or use custom_minimum_size
$Control.custom_minimum_size = Vector2(200, 150)

Hardcoding pixel values without scaling:

# ❌ Bad - too small on hiDPI
var padding = 10

# ✅ Good - scale with content_scale_factor
var padding = 10 * get_tree().root.content_scale_factor

Manual font size calculations:

# ❌ Bad - inconsistent across displays
label.add_theme_font_size_override("font_size", 24)

# ✅ Good - use theme with dynamic fonts
# Set in Theme resource with multiple sizes

Forgetting to handle window resize:

# ✅ Good - subscribe to resize signal
func _ready():
    get_viewport().size_changed.connect(_on_viewport_size_changed)
    _on_viewport_size_changed()

func _on_viewport_size_changed():
    # Recalculate responsive layout
    pass

Quick Reference

TaskGodot 3.xGodot 4.x
Theme overrideadd_stylebox_override()add_theme_stylebox_override()
Font overrideadd_font_override()add_theme_font_override()
Color overrideadd_color_override()add_theme_color_override()
Constant overrideadd_constant_override()add_theme_constant_override()
Size overriderect_min_sizecustom_minimum_size
Positionrect_positionposition
Sizerect_sizesize
Global positionrect_global_positionglobal_position
BBCode color[color=red][color=ff0000] or [color=#ff0000]
BBCode image[img]path[/​img][img=widthxheight]path[/​img]
hiDPI settingProjectSettings.display/​window/​dpi/​allow_hidpiDisplay > Window > Stretch > Mode

Migration Checklist

  • Extract all hardcoded styles to Theme resources
  • Replace rect_* properties with position/​size
  • Update BBCode syntax (colors, images)
  • Configure hiDPI in project settings
  • Convert manual positioning to anchor/​layout system
  • Test on multiple resolutions and DPIs
  • Add viewport resize handling
  • Create custom controls for repeated patterns

More skills from Asreonn

godot-sync-camera-positions logo
Asreonn/godot-superpowers

godot-sync-camera-positions

Use when Godot background layers or elements follow the camera at runtime but show incorrect position in editor. Detects camera-following patterns and syncs editor position to match typical runtime state. Makes editor preview accurately show what players will see during gameplay.

4 0
View
godot-refactor logo
Asreonn/godot-superpowers

godot-refactor

Use when Godot project has code-created objects, tight coupling via direct references, monolithic scripts over 150 lines, or needs scene-first architecture with signals and composition. Orchestrates all 5 code quality mini-skills: extract-to-scenes, split-scripts, add-signals, extract-resources, ...

4 0
View
godot-split-scripts logo
Asreonn/godot-superpowers

godot-split-scripts

Use when Godot scripts exceed 150 lines or have multiple responsibilities. Detects scripts doing too many things (player movement + combat + inventory + UI). Automatically splits into focused scripts following Single Responsibility Principle, preserves behavior exactly, and creates git commits pe...

4 0
View
godot-convert-shaders logo
Asreonn/godot-superpowers

godot-convert-shaders

Converts Godot 3.x shader code to Godot 4.x shader syntax. Updates SCREEN_TEXTURE to screen_texture uniform, DEPTH_TEXTURE to depth_texture uniform, texture() function changes, built-in varyings updates, and light function signature changes. Essential for rendering and visual effect migrations.

4 0
View
godot-migrate-tilemap logo
Asreonn/godot-superpowers

godot-migrate-tilemap

Migrates legacy TileMap (Godot 4.0-4.2) to new TileMapLayer system (Godot 4.3+). Handles TileMap node conversion, API migration (set_cell to set_cells_terrain_connect), TileSet resource updates, physics layer mapping, navigation layer conversion, and custom data preservation. Essential for upgrad...

4 0
View
godot-setup-animationtree logo
Asreonn/godot-superpowers

godot-setup-animationtree

Use when setting up AnimationTree nodes for state machine-driven animation, creating AnimationNodeStateMachine graphs, configuring BlendSpace2D/3D for locomotion blending, implementing state transition conditions, or creating animation blend trees for complex animation mixing. Supports player cha...

4 0
View
godot-extract-resources logo
Asreonn/godot-superpowers

godot-extract-resources

Use when Godot code has hardcoded game data in const arrays, dictionaries, or embedded values. Detects inline data like enemy stats, item definitions, level configurations. Automatically extracts to .tres resource files, making data visible in editor, easily modifiable, and supports data-driven d...

4 0
View
godot-modernize-input logo
Asreonn/godot-superpowers

godot-modernize-input

Use when handling input in Godot 4.x projects and need to modernize patterns. Generates Input Map configurations from hardcoded key checks, sets up joypad rumble (Godot 4.x feature), implements gyroscope/accelerometer input on mobile, creates context-sensitive input handling for different game st...

4 0
View
godot-sync-parallax logo
Asreonn/godot-superpowers

godot-sync-parallax

Use when Godot ParallaxBackground/ParallaxLayer nodes show incorrect positions in editor due to parallax multipliers. Calculates correct editor positions based on camera start position and parallax motion scale. Makes parallax layers preview realistically in editor, matching gameplay appearance.

4 0
View
godot-setup-export logo
Asreonn/godot-superpowers

godot-setup-export

Use when setting up multi-platform exports for Godot projects, configuring export presets, icons, feature tags, build scripts, or CI/CD pipelines

4 0
View
godot-generate-tests logo
Asreonn/godot-superpowers

godot-generate-tests

Use when developing Godot games and need comprehensive test coverage for GDScript classes, signals, scene initialization, and integration flows. Generates GUT framework unit tests, integration tests, mock/stub helpers, and CI/CD test runner configuration.

4 0
View
godot-fix-positions logo
Asreonn/godot-superpowers

godot-fix-positions

Use when Godot project has position conflicts between editor (.tscn) and code (.gd), camera-following backgrounds, or runtime positions don't match editor preview. Orchestrates all 3 position sync mini-skills: sync-static-positions, sync-camera-positions, and sync-parallax. Each operation targets...

4 0
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View