CppDepend
Home/Docs/Analyze an Unreal Engine Project

How to Analyze an Unreal Engine Project with CppDepend

Prerequisites

Unreal Engine (UE) projects rely on custom build tools (UnrealBuildTool / UBT) and engine-generated reflection headers (*.generated.h), making them different from standard Visual Studio or CMake projects.

This guide walks you through analyzing your Unreal Engine game modules and engine source code using CppDepend.

  • •Unreal Engine 4 or 5 installed.
  • •Your UE project built at least once in Development Editor configuration (to generate required headers and build files).
  • •CppDepend installed (Standalone or Visual Studio Plugin).

Step 1: Export the Compilation Database (JSON)

Since Unreal Engine uses UnrealBuildTool (UBT) rather than native Visual Studio project structures, generating a compile_commands.json file guarantees 100% accurate include paths, preprocessor defines, and compiler options.

  • 1.Open your terminal or Command Prompt.
  • 2.Navigate to your Unreal Engine installation directory:
cd "C:\Program Files\Epic Games\UE_5.x\Engine\Build\BatchFiles"
  • 3.Run UnrealBuildTool with the -mode=GenerateClangDatabase flag pointing to your project:
Build.bat YourProjectNameEditor Win64 Development -Project="C:\Path\To\YourProject.uproject" -mode=GenerateClangDatabase

This creates a compile_commands.json file inside your project root directory or .unittest / Saved folder.

Alternative (Visual Studio Solution): if you generated a Visual Studio solution (.sln) from your .uproject, CppDepend can also inspect the .vcxproj files directly. However, the JSON Compilation Database method is recommended for faster and more accurate parsing.

Step 2: Create a New CppDepend Project

  • 1.Launch CppDepend.
  • 2.Click Create a new CppDepend Project.
  • 3.Name your project (e.g., MyGame_Analysis) and set the output directory.

Step 3: Import Project Inputs

  • 1.Under Analysis Inputs, click Add.
  • 2.Select Import CMake / Clang JSON Compilation Database (compile_commands.json).
  • 3.Browse to and select the compile_commands.json generated in Step 1.

(Optional Filter): if you only want to analyze your custom game modules (and skip analyzing all of Unreal Engine's core codebase to save time), filter out the engine paths under Exclude Files:

Add path rule: *\Engine\Source\*

Step 4: Run the Analysis

Click Run Analysis (or F5).

CppDepend will parse the source files, resolve includes, build the internal Code Model, and calculate code metrics.

Once completed, the dashboard will open.

Step 5: Write Custom CQLinq Rules for Unreal Engine

Unreal Engine has specific architectural patterns (such as Garbage Collection, UCLASS, UPROPERTY, and memory management). You can use CQLinq to enforce engine-specific best practices:

Example 1: Find Raw Pointer UPROPERTY Fields Missing Garbage Collection Protection

// <Name>UE001: Raw UObject pointers must be marked with UPROPERTY()</Name>
from f in Application.Fields
where f.Type.IsDerivedFrom("UObject") && 
      !f.IsStatic && 
      !f.HasAttribute("UPROPERTY")
select new { 
    Field = f, 
    Severity = Severity.High,
    FixHint = "Raw UObject pointers without UPROPERTY() risk being garbage collected unexpectedly."
}

Example 2: Detect Heavy Calculations inside Tick() Functions

// <Name>UE002: Overly Complex Tick Functions</Name>
from m in Application.Methods
where m.SimpleName.Equals("Tick") && 
      m.CyclomaticComplexity > 15
select new { 
    TickMethod = m, 
    m.CyclomaticComplexity,
    FixHint = "Refactor complex tick logic into event-driven timers or worker threads."
}

Tips & Best Practices for UE Analysis

  • •Disable Unity Builds for Precision: Unreal Engine uses "Unity builds" (combining multiple .cpp files into single translation units) to speed up compilation. For line-by-line static analysis precision, disable Unity builds in your YourGame.Target.cs file by adding:
bUseUnityBuild = false;
  • •CI/CD Integration: you can automate this analysis in your build pipeline using CppDepend.Console.exe during nightly automated builds.

Try CppDepend Today

Start your 14-day free trial with full access to all documentation features. No credit card required.