Install Asset
Install via Godot
To maintain one source of truth, Godot Asset Library is just a mirror of the old asset library so you can download directly on Godot via the integrated asset library browser
Quick Information
A pre-run validation tool for Godot 4.x C# that ensures exported fields marked are assigned in the Inspector, preventing runtime null reference errors.
ο»Ώ# FieldValidator for Godot (C#)
FieldValidator is a lightweight utility for Godot 4.x C# projects. It ensures that your [Export] fields are properly assigned in the Inspector before the game starts, shifting potential runtime crashes to a pre-run validation phase.
If a mandatory field is left empty, the plugin blocks the build and prints a detailed error message in the console, identifying the specific Scene, Node, or Resource.
π‘ Why Use This?
In standard Godot development, scripts often rely on other nodes or resources. This plugin promotes a safer and cleaner architecture:
- Explicit Dependency Management: By using
[Export]combined with[MustSet], you make node dependencies explicit in the Inspector. Anyone looking at the scene instantly knows exactly what a script needs to function. - Eliminate Brittle
GetNode()Calls: Instead of usingGetNode("Path/To/Node")or%UniqueNamein_Ready()βwhich can fail silently or crash the game if the tree structure changesβyou can assign references via the Inspector and let this plugin guarantee they are valid before the code ever runs. - Fail Fast: Catching a missing reference at build-time is much cheaper than debugging a
NullReferenceException10 minutes into a playtest.
β¨ Features
- Pre-run Validation: Automatically scans your project when you click "Play".
- Scene & Resource Support: Validates nodes within
.tscnfiles and properties in.tres/.resfiles. - Recursive Checking: Deep-scans nested Resources and Child Nodes.
- Ignore System: Easily exclude specific folders (like third-party addons) via a
.fieldignorefile.
Note: The plugin performs a global check of the entire project every time you run the game, regardless of which specific scene you are launching. This ensures project-wide consistency but may take a moment in very large projects (use
.fieldignoreto optimize).
π Installation
- Copy the
addons/FieldValidatorfolder into your project'sres://addons/directory. - Build your C# solution in Godot.
- Go to Project -> Project Settings -> Plugins and enable FieldValidator.
π Usage
Simply apply the provided attributes to any exported field or property in your C# scripts:
1. [MustSet]
Use this on single object references (Nodes, Resources, etc.) that must be assigned in the Inspector.
using FieldValidator;
public partial class MyPlayer : CharacterBody2D
{
[Export] [MustSet]
private required Sprite2D _sprite = null!; // Build will fail if this is empty
}
2. [MemberMustSet]
Use this on collections (Arrays or Lists) to ensure that every single slot in the collection has been assigned a value.
using FieldValidator;
public partial class EnemySpawner : Node
{
[Export] [MemberMustSet]
private Godot.Collections.Array<PackedScene> _enemyTypes; // Fails if any index is null
}
π Example Output
When a field is missing, the Godot console will output the following and block the game from starting:
[β Error] [Resource: res://resources/Actions/AnyActionDef.tres]->_transitions[4] :: _conditions -> Array element at [2] is null (MemberMustSet)
[β Error] [Scene: res://scenes/Characters/Player/Player.tscn] :: [Node: MotorComponent] :: TimeContext -> Assignment required (MustSet)
[β Error] [Scene: res://scenes/Test/Playground.tscn] :: [Node: MotorComponent] :: TimeContext -> Assignment required (MustSet)
β Validation Failed! Found 3 null reference errors. Execution blocked.
Duration: 6.04ms
βοΈ Configuration (.fieldignore)
The first time the plugin runs, it creates a .fieldignore file in your project root (res://). You can add paths to this file (one per line) to skip validation for specific folders or files.
Example .fieldignore:
# Ignore Path
.godot/
.vs/
.vscode/
res://addons/
src/
π Manual Validation
You can also trigger a full project scan manually at any time:
- Open
FieldValidatorScript.csin the FileSystem dock. - Right-click it and select Run.
- View the detailed report in the Output bottom panel.
π Future Outlook
This plugin is designed to be extensible. While it currently focuses on null-checks via MustSet and MemberMustSet, the architecture allows for future attributes such as range validation, string pattern matching, or custom logic constraints.
A pre-run validation tool for Godot 4.x C# that ensures exported fields marked are assigned in the Inspector, preventing runtime null reference errors.
Reviews
Quick Information
A pre-run validation tool for Godot 4.x C# that ensures exported fields marked are assigned in the Inspector, preventing runtime null reference errors.