Godot 4.x GDScript Best Practices
Guide AI agents in writing high-quality GDScript code for Godot 4.x. This skill provides coding standards, architecture patterns, and templates for game development.
When to Use This Skill
Use this skill when:
- Generating new GDScript code
- Creating or organizing Godot scenes
- Designing game architecture and node hierarchies
- Implementing state machines, object pools, or save systems
- Answering questions about GDScript patterns or Godot conventions
- Reviewing GDScript code for quality issues
Do NOT use this skill when:
- Working with C# in Godot (use C# patterns)
- Working with Godot 3.x (syntax differs significantly)
- Using GDExtension/C++ (different paradigm)
- Working with Godot's visual scripting
Core Principles
1. Naming Conventions
Follow GDScript naming standards consistently:
2. Type Hints (Static Typing)
Use explicit type hints everywhere for autocomplete and error detection:
3. Node References
Use modern patterns for stable, refactor-friendly references:
4. Signal-Driven Architecture
Use signals for decoupled communication. Follow "signal up, call down":
5. Resource Loading
Choose the right loading strategy:
Quick Reference
Code Generation Guidelines
Script Structure
Order sections consistently:
Export Annotations
Use exports for editor-configurable values:
Common Game Patterns
State Machine (Overview)
Use enum-based state machines for simple cases:
See references/patterns/state-machine.md for advanced implementations.
Object Pooling (Overview)
Reuse objects to avoid instantiation cost:
See references/patterns/object-pooling.md for complete implementation.
Save/Load (Overview)
Use Resources or JSON for save data:
See references/patterns/save-load-system.md for comprehensive guide.
Common Anti-Patterns
Additional Resources
Pattern Guides
references/patterns/state-machine.md- Full state machine implementationsreferences/patterns/object-pooling.md- Complete pooling systemreferences/patterns/save-load-system.md- Comprehensive save/load guidereferences/patterns/input-handling.md- Input buffering and rebinding
Architecture
references/architecture/project-structure.md- Directory organizationreferences/architecture/scene-composition.md- Scene design patternsreferences/architecture/node-communication.md- Signals vs direct calls
GDScript Deep Dives
references/gdscript/type-system.md- Static typing in depthreferences/gdscript/coroutines-await.md- Async patterns with await
Templates
assets/templates/base-script.gd.md- Standard script templateassets/templates/state-machine.gd.md- State machine templateassets/templates/autoload-manager.gd.md- Autoload singleton template
Limitations
- GDScript only (not C#, GDExtension, or VisualScript)
- Godot 4.x syntax (some patterns differ from 3.x)
- Game-focused patterns (not editor plugin development)
- No runtime validation scripts (GDScript requires Godot runtime)


