Getting Started
On first use, the AutoFields Settings window will automatically appear:

This window allows you to configure default namespaces, script folder paths, field naming styles, and automatic tracking behavior.
Settings
Default Namespace
Sets the base namespace used for generated scripts.
Default Scripts Folder
Controls where the generated C# files are placed. You can use{Namespace}
as a placeholder.{Namespace}
will be replaced with DefaultScriptsNamespace.Any dots in the namespace will be replaced with the directory separator.Example:Namespace: MyCompany.Scripts.ToolkitFolder: Assets/Scripts/UI/{Namespace}/Result: Assets/Scripts/UI/MyCompany/Scripts/Toolkit/Track All VisualTreeAssets
If enabled, AutoFields will track all UXML files in the project automatically. Assets labeled DoNotTrack or located in the Packages will be skipped.
Property Name Case
Choose between PascalCase or camelCase for generated property names.
Delete Scripts for Untracked Assets
Automatically remove scripts if their source UXML files are no longer tracked.
Delete Scripts for Deleted Assets
Automatically remove scripts if their source UXML files are removed.
Enabling AutoFields
To activate AutoFields functionality:
Review or modify the settings as needed.
Click the Enable AutoFields button.
Once enabled:
AutoFields will immediately generate scripts for existing UXML files if Track All VisualTreeAssets is enabled.
Any new or modified tracked UXML files will automatically trigger script generation according to the settings.
Next Steps
Mark UXML file as tracked using the context menu (right click on asset in the Project window) AutoFields / Track VisualTreeAsset if Track All VisualTreeAssets is disabled
Add
name="element-name"
attributes to elements in your UXML file and save it.Access these elements in your script by simply using the generated field or property:
var doc = GetComponent<UIDocument>(); var ui = new AutoGenerated.AutoFieldsSample(doc.rootVisualElement); ui.TestLabel.text = "Changed in Runtime"; ui.TestButton.clicked += () => Debug.Log("Button Click"); ui.TestButton.text = "Added Click Event in Runtime";
Generated Class Names
Each generated script will contain a single class whose name is derived from the UXML file name. The file name is converted to a valid C# class name using PascalCase formatting. Invalid characters are removed.
For the UXML file my-settings-panel.uxml
will be created MySettingsPanel.generated.cs
script with class name: MySettingsPanel
.
You can then use this class as a partial or base class for your UI logic, with all named elements available as strongly-typed fields or properties.
HotReload
AutoFields works best in combination with the HotReload plugin (available on the Asset Store).
Renamed or newly added UI elements (name attributes) will show up almost instantly as properties in the generated class.
Changes to existing scripts are picked up without recompilation.
However, newly generated scripts (for new UXML files) still require a Unity scripts recompilation before they become available.