Generated Code and Templates

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.

Generated class contains:

  • A constructor that takes a VisualElement and calls FindFields(...)

  • One public property for each element in the UXML file with a name attribute

  • A FindFields(...) method that automatically maps those names using Q<>()

You are free to:

  • Change the namespace

  • Rename the generated class

  • Move the file to a different folder

AutoFields will continue to detect and update the class correctly, as long as the original generated fields section markers are preserved.

You can fully customize the structure and style of generated code by specifying your own template files in the AutoFields for UI Toolkit / Assets / Templates.asset:

  • template-ui-class.txt is template for the class

  • template-ui-fields.txt is template for the fields section