top of page

T4 Source code generator

Paid Unity plugin for generating source code files from template files.


Template is a mix of text fields and program logic which generates a text file upon execution. C# is used for program logic. Generated file can be any type of text file – resource file, source code for any language, web page mark-up etc.


  • Customized generation directly from Unity editor.

  • Automated generation triggered by special events.

Use Cases

  • Generating source code using metadata

    • Access classes for databases using data scheme.

    • Network API client using Swagger metadata.

    • Access classes for game data.

  • Generating source code to work wth game resources.

  • Generating source code using DSL

  • Collecting environment information into game resource files.


Requires Unity 4.7 or later.
Platforms: PC/Mac.

How to use

Create a file with extension .tt in your project or copy it from elsewhere. Select your fule in Project window, then use Inspector window to adjust settings for generation from template. Click "Generate" to make sure template is valid. Generation errors are displayed in Console window.


  • Output Type – type of a file to generate

    • Content – common generation result (Microsoft nomenclature: "Design-time T4 text templates").

    • Generator – generator class which provides template execution result if TransformText() is called. (Microsoft nomenclature: "Run time T4 text templates").

  • Output Path – Path to the file to which generation result will be written. If not specified, file will be created at the same location with the same name as the original template (plus file extension provided by the template).

  • Auto-Gen Triggers – events which trigger automatic generation.

    • Code Compilation – each time code is compiled in Unity editor.

    • Asset Changes – each time specified asset is modified. Assets are specified by Assets to Watch list.

  • Auto-Gen Delay (Ms) – delay (in milliseconds) before autogeneration is launched.

  • Assets to Watch – list of assets and folders which trigger auto-generation if modified.


Template example

The following template is used to generate C# class with information about the environment Unity editor is launched in.

Screenshot 2023-04-01 210135.png
bottom of page