Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


Code analysis and source generation

Use analyzers to inspect your code for style, quality, and other issues.
Read time 1 minuteLast updated 13 days ago

A code analyzer examines your source code and reports diagnostics to help find errors or enforce rules. A source generator runs during compilation and creates additional source code that becomes part of your program.
In the C#/.NET ecosystem, source generators and analyzers are both built on the same Roslyn compiler platform, and analyzers are typically referred to as Roslyn analyzers.
Both analyzers and source generators are imported as managed plugins to your Unity project. You can either write your own analyzer or source generator or import existing third party libraries.
Note
Roslyn analyzers are only compatible with the IDEs that Unity supports.
For more information about how to write and use Roslyn analyzers, refer to Analyzer Configuration and Get started with Roslyn analyzers in the Microsoft documentation.

Topic

Description

Create and use a source generatorCreate a simple source generator and configure the Unity Editor to use it for your Unity project code.
Create and use a Roslyn analyzerCreate a simple Roslyn analyzer and configure the Unity Editor to use it for your Unity project code.
Install and use an existing analyzer or source generatorDownload an existing code analyzer or source generator and configure the Unity Editor to use it for your Unity project code.
Additional files for Roslyn analyzers and source generatorsDefine additional text files for Roslyn analyzers or source generators to use.
Analyzer scope and rule set filesControl which parts of your code are subject to code analysis and customize diagnostic levels per-assembly.

Additional resources