| name | godot-code-review |
| description | Use when reviewing GDScript or C# Godot code — checklist of best practices, common anti-patterns, and Godot-specific pitfalls |
Godot Code Review
A structured review guide for Godot 4.3+ projects covering GDScript and C#. Work through each checklist section, then produce a review summary using the output template at the end.
Related skills: godot-testing for TDD and test coverage, scene-organization for scene tree best practices, godot-optimization for performance review.
1. Node & Scene Architecture
Anti-pattern — get_parent() chain
# BAD: tight coupling, breaks if the tree changes
func take_damage(amount: int) -> void:
get_parent().get_parent().get_node("HUD").update_health(health)
public void TakeDamage(int amount)
{
GetParent().GetParent().GetNode("HUD").Call("UpdateHealth", _health);
}
Fix — emit a signal instead
# GOOD: parent/ancestor listens; child stays decoupled
signal health_changed(new_health: int)
func take_damage(amount: int) -> void:
health -= amount
health_changed.emit(health)
[Signal]
public delegate void HealthChangedEventHandler(int newHealth);
public void TakeDamage(int amount)
{
_health -= amount;
EmitSignal(SignalName.HealthChanged, _health);
}
2. GDScript Style
Bad — untyped
var speed = 200
var health = 100
func move(direction):
position += direction * speed
func heal(amount):
health += amount
return health
float speed = 200;
int health = 100;
public void Move(object direction)
{
Position += (Vector2)direction * speed;
}
public object Heal(object amount)
{
health += (int)amount;
return health;
}
Good — typed
class_name PlayerController
extends CharacterBody2D
signal health_changed(new_health: int)
signal player_died()
const MAX_HEALTH: int = 100
const BASE_SPEED: float = 200.0
@export var speed: float = BASE_SPEED
@export var max_health: int = MAX_HEALTH
var health: int = max_health
func move(direction: Vector2) -> void:
velocity = direction * speed
move_and_slide()
func heal(amount: int) -> int:
health = mini(health + amount, max_health)
health_changed.emit(health)
return health
public partial class PlayerController : CharacterBody2D
{
[Signal]
public delegate void HealthChangedEventHandler(int newHealth);
[Signal]
public delegate void PlayerDiedEventHandler();
private const int MaxHealth = 100;
private const float BaseSpeed = 200f;
[Export] public float Speed { get; set; } = BaseSpeed;
[Export] public int MaxHp { get; set; } = MaxHealth;
private int _health;
public override void _Ready()
{
_health = MaxHp;
}
public void Move(Vector2 direction)
{
Velocity = direction * Speed;
MoveAndSlide();
}
public int Heal( amount)
{
_health = Mathf.Min(_health + amount, MaxHp);
EmitSignal(SignalName.HealthChanged, _health);
_health;
}
}
3. C# Style
public partial class PlayerController : CharacterBody2D
{
[Signal]
public delegate void HealthChangedEventHandler(int newHealth);
[Export] public float Speed { get; set; } = 200f;
[Export] public int MaxHealth { get; set; } = 100;
private int _health;
private AnimationPlayer _animationPlayer = null!;
public override void _Ready()
{
_animationPlayer = GetNode<AnimationPlayer>("AnimationPlayer");
if (_animationPlayer is null)
GD.PushError("AnimationPlayer node not found on PlayerController");
_health = MaxHealth;
}
public void TakeDamage(int amount)
{
_health = Mathf.Max(_health - amount, 0);
EmitSignal(SignalName.HealthChanged, _health);
}
}
4. Performance
Anti-pattern — uncached node lookup in _process()
# BAD: get_node() traverses the tree every frame
func _process(delta: float) -> void:
get_node("HUD/HealthBar").value = health
get_node("HUD/Label").text = str(health)
public override void _Process(double delta)
{
GetNode<ProgressBar>("HUD/HealthBar").Value = _health;
GetNode<Label>("HUD/Label").Text = _health.ToString();
}
Fix — cache with @onready
# GOOD: resolved once at scene load
@onready var _health_bar: ProgressBar = $HUD/HealthBar
@onready var _health_label: Label = $HUD/Label
func _process(delta: float) -> void:
_health_bar.value = health
_health_label.text = str(health)
private ProgressBar _healthBar = null!;
private Label _healthLabel = null!;
public override void _Ready()
{
_healthBar = GetNode<ProgressBar>("HUD/HealthBar");
_healthLabel = GetNode<Label>("HUD/Label");
}
public override void _Process(double delta)
{
_healthBar.Value = _health;
_healthLabel.Text = _health.ToString();
}
StringName in hot paths
# BAD: new String allocation compared each frame
if animation_name == "run":
pass
# GOOD: StringName literal, no allocation
if animation_name == &"run":
pass
if (animationName == "run") { }
private static readonly StringName RunAnim = new("run");
public override void _Process(double delta)
{
if (animationName == RunAnim) { }
}
5. Input Handling
# Continuous movement — physics process
func _physics_process(delta: float) -> void:
var direction: Vector2 = Input.get_vector(
&"ui_left", &"ui_right", &"ui_up", &"ui_down"
)
velocity = direction * speed
move_and_slide()
# Discrete action — unhandled input
func _unhandled_input(event: InputEvent) -> void:
if event.is_action_pressed(&"jump"):
_jump()
public override void _PhysicsProcess(double delta)
{
Vector2 direction = Input.GetVector(
"ui_left", "ui_right", "ui_up", "ui_down"
);
Velocity = direction * Speed;
MoveAndSlide();
}
public override void _UnhandledInput(InputEvent @event)
{
if (@event.IsActionPressed("jump"))
{
Jump();
}
}
6. Signals & Communication
# Good signal names
signal health_changed(new_health: int) # past tense
signal enemy_died() # past tense
signal item_collected(item: ItemData) # past tense
# Bad signal names (present/imperative tense)
# signal update_health(value: int)
# signal die()
# signal collect_item(item: ItemData)
[Signal]
public delegate void HealthChangedEventHandler(int newHealth);
[Signal]
public delegate void EnemyDiedEventHandler();
[Signal]
public delegate void ItemCollectedEventHandler(ItemData item);
# Parent connects to child signal in _ready()
func _ready() -> void:
$Enemy.enemy_died.connect(_on_enemy_died)
$Player.health_changed.connect(_on_player_health_changed)
public override void _Ready()
{
GetNode<Enemy>("Enemy").EnemyDied += OnEnemyDied;
GetNode<Player>("Player").HealthChanged += OnPlayerHealthChanged;
}
7. Resource Management
# Compile-time — path is validated by the editor
const BULLET_SCENE: PackedScene = preload("res://scenes/bullet.tscn")
# Runtime — path comes from data
func _load_level(path: String) -> void:
ResourceLoader.load_threaded_request(path)
func _check_load(path: String) -> void:
if ResourceLoader.load_threaded_get_status(path) == ResourceLoader.THREAD_LOAD_LOADED:
var scene: PackedScene = ResourceLoader.load_threaded_get(path)
get_tree().change_scene_to_packed(scene)
# Cleanup
func _on_enemy_died() -> void:
queue_free() # safe — deferred until end of frame
private static readonly PackedScene BulletScene =
GD.Load<PackedScene>("res://scenes/bullet.tscn");
private void LoadLevel(string path)
{
ResourceLoader.LoadThreadedRequest(path);
}
private void CheckLoad(string path)
{
if (ResourceLoader.LoadThreadedGetStatus(path) == ResourceLoader.ThreadLoadStatus.Loaded)
{
var scene = ResourceLoader.LoadThreadedGet(path) as PackedScene;
GetTree().ChangeSceneToPacked(scene);
}
}
private void OnEnemyDied()
{
QueueFree();
}
8. Error-Prone Patterns
| Pattern | Problem | Fix |
|---|
await get_tree().create_timer(t).timeout after queue_free() | Timer signal fires on a freed node, causing errors | Check is_instance_valid(self) after await, or use create_tween() which auto-stops |
Fragile node paths like $A/B/C/D/E | Breaks silently when the scene tree is reorganized | Refactor to direct children + signals, or export a NodePath |
call_deferred() used everywhere | Defers are appropriate for cross-frame safety, not a general solution; overuse hides real design issues | Only defer when crossing physics/main thread boundaries or breaking a call cycle |
set_physics_process(true) called inside _physics_process() | Redundant call every frame; wastes CPU | Call once at the point you actually want to enable/disable processing |
Directly setting position on a CharacterBody2D | Bypasses collision; teleports the body and can cause tunnelling | Use move_and_slide() with velocity; only set position/global_position for intentional teleports |
9. Review Output Format
Use this template when delivering a review:
## Code Review — <FileName or Feature>
### Critical
Issues that will cause bugs, crashes, or significant performance problems.
- [ ] <node/line> — <issue> — **Suggested fix:** <fix>
### Improvements
Code quality, style, or maintainability concerns that should be addressed.
- [ ] <node/line> — <issue> — **Suggested fix:** <fix>
### Positive
What the code does well — reinforce good patterns.
- <observation>
---
Reviewed against: Godot 4.3+ best practices
Example
## Code Review — PlayerController.gd
### Critical
- [ ] _process() line 42 — `get_node("HUD/HealthBar")` called every frame — **Suggested fix:** Cache with `@onready var _health_bar: ProgressBar = $HUD/HealthBar`
- [ ] take_damage() line 67 — no type hints on parameter or return — **Suggested fix:** `func take_damage(amount: int) -> void:`
### Improvements
- [ ] Line 12 — signal `updateHealth` should be past tense — **Suggested fix:** Rename to `health_changed`
- [ ] Line 8 — `var speed = 200` missing type hint — **Suggested fix:** `var speed: float = 200.0`
### Positive
- Signals are declared at the top of the file
- Constants correctly use SCREAMING_SNAKE_CASE
- `queue_free()` used correctly for cleanup
---
Reviewed against: Godot 4.3+ best practices