Our website uses cookies to enhance your browsing experience.
Accept
to the top
close form

Fill out the form in 2 simple steps below:

Your contact information:

Step 1
Congratulations! This is your promo code!

Desired license type:

Step 2
Team license
Enterprise license
** By clicking this button you agree to our Privacy Policy statement
close form
Request our prices
New License
License Renewal
--Select currency--
USD
EUR
* By clicking this button you agree to our Privacy Policy statement

close form
Free PVS‑Studio license for Microsoft MVP specialists
* By clicking this button you agree to our Privacy Policy statement

close form
To get the licence for your open-source project, please fill out this form
* By clicking this button you agree to our Privacy Policy statement

close form
I am interested to try it on the platforms:
* By clicking this button you agree to our Privacy Policy statement

close form
check circle
Message submitted.

Your message has been sent. We will email you at


If you do not see the email in your inbox, please check if it is filtered to one of the following folders:

  • Promotion
  • Updates
  • Spam

Webinar: Evaluation - 05.12

>
>
How to analyze Unity projects with PVS-…
menu mobile close menu
Analyzer diagnostics
General Analysis (C++)
General Analysis (C#)
General Analysis (Java)
Micro-Optimizations (C++)
Diagnosis of 64-bit errors (Viva64, C++)
Customer specific requests (C++)
MISRA errors
AUTOSAR errors
OWASP errors (C++)
OWASP errors (C#)
Problems related to code analyzer
Additional information
toggle menu Contents

How to analyze Unity projects with PVS-Studio

Jun 22 2022

Unity projects written in C# can be analyzed by PVS-Studio from the console or IDE. The Unity project you intend to check should be built successfully so that the analysis results are as correct and complete as possible.

You can download the analyzer distribution from this page.

Before you start working with PVS-Studio, you need to enter the license data. You can read more about entering a license here.

Checking the project with PVS-Studio plugins for IDE

How to open the Unity project in Visual Studio and JetBrains Rider

Before you start working with the Unity project code, choose your preferred script editor in the Unity settings. Use the "External Script Editor" parameter on the "External Tools" tab in the "Preferences" window. To open the window, use the "Edit" -> "Preferences" menu option in the Unity editor:

UnityGuide/image1.png

After that, you can open the Unity project in the IDE — use the "Assets" -> "Open C# Project" option in the Unity editor:

UnityGuide/image2.png

You can also open the generated Unity .sln file in the IDE. If there is no .sln file, you need to perform the actions described above in the Unity editor. That way the .sln file will be generated.

PVS-Studio and Visual Studio

You can analyze a Unity project in Visual Studio. For more information on how to use the PVS-Studio plugin, see the documentation.

The analysis can be performed for the following elements:

  • the whole Unity project (.sln);
  • .csproj projects generated by Assembly Definition;
  • individual .cs files.

You can run the analysis from the PVS-Studio plugin submenu via the "Extensions" menu on the top menu bar:

UnityGuide/image3.png

Also, it is possible to start the analysis from the "Solution Explorer" window via the context menu by clicking on the solution element.

The analysis results appear in the "PVS-Studio" window:

UnityGuide/image4.png

PVS-Studio and JetBrains Rider

You can analyze a Unity project from JetBrains Rider. The capabilities of PVS-Studio plugin for JetBrains Rider and its capabilities are similar to those for the Visual Studio plugin. Detailed instructions on how to use the plugin for JetBrains Rider are available at the link.

You can run the analysis from the main menu:

UnityGuide/image5.png

How to check a project from the command line

You can run PVS-Studio from the command line. This way of running PVS-Studio is more convenient if you want to integrate the project analysis into your CI/CD infrastructure.

A guide on how to use the CLI version of PVS-Studio is available here.

You can check the entire solution (sln), individual projects (csproj) or some set of source code files. In the latter case, the path to the .sln/.csproj file is also required.

To analyze C# projects on Windows, use "PVS-Studio_Cmd.exe ", and on Unix-like systems — "pvs-studio-dotnet".

Example of launching PVS-Studio via the CLI on Windows:

PVS-Studio_Cmd.exe -t D:\UnityProjects\MyProject\MyProject.sln

Example of running PVS-Studio via the CLI on Unix-like systems:

pvs-studio-dotnet -t ./MyUnityProject.sln

By default, the analysis report is saved in the following formats:

  • plog on Windows;
  • json on Linux and macOS.

You can open reports in the PVS-Studio's plugins for IDEs.

Note. Rider does not support reports in the plog format. In addition, the conversion of plog reports is not supported under Linux and macOS.

Below is the PVS-Studio plugin's menu for Visual Studio:

UnityGuide/image6.png

It is possible to convert reports into a more convenient format.

To convert the reports, use the CLI utulity — PlogConverter. The name of the utility depends on the platform. It is "PlogConverter.exe " for Windows platform and "plog-converter" for Unix-like systems. To get more detailed information about the utility, see the documentation.

Example of converting a report into HTML format on Windows (should be entered in one line):

PlogConverter.exe D:\UnityProjects\MyProject\MyProject.plog
-t FullHtml
-o D:\UnityProjects\MyProject\

Example of converting a report into HTML format on Unix-like systems:

plog-converter –t fullhtml ./ ./MyProject.plog

These commands convert the report into HTML format, which is convenient for viewing in a browser and for mailing. Example of a report in the FullHtml format:

UnityGuide/image7.png

Issues that may occur during analysis

The solution file has two projects named "UnityEngine.UI"

If the "Player projects" option is enabled in the C# project generation settings, the Unity editor generates a solution file with duplicate project names. When analyzing a project with PVS-Studio, you can get the error of the following type: The solution file has two projects named "UnityEngine.UI". To perform the analysis, this option must be disabled.

UnityGuide/image9.png

After that, you may need to regenerate project files. The "Regenerate project files" button below is right for this.

Once the duplicates from the sln-file are gone, the analysis should work normally. This problem with duplicate project names is described in more detail in following article.

Do not modify project files during analysis

During the analysis, we recommend that you do not perform any actions that may modify the sln/csproj files or source code files. For example, actions such as changing or creating Assembly Definitions and Assembly Definition References, or creating new scripts.