Version: Unity 6.6 Beta (6000.6)
LanguageEnglish
  • C#

BuildHistory

class in UnityEditor.Build

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

Provides access to the build history generated during builds.

This class provides programmatic access to the build history: for each Player or Content Directory build, Unity creates a "build report directory" that holds the BuildReport file and the supporting data captured during that build. Use this class to enumerate builds, query their summaries, and locate the files in their build report directories. For a conceptual overview of the build history and a description of each file it contains, refer to Build history.

Build report directories are self-contained and portable. The BuildHistory API can read a build report directory even if a different machine or a different Unity project produced it, so you can consolidate build reports from multiple build servers into a single build history folder.

Unity assigns each build a unique GUID, which the BuildHistory API uses to precisely identify each build. For more information, refer to BuildReportSummary.BuildSessionGUID.

Retention policy

To prevent unbounded growth of the build history folder, Unity applies a retention policy at the start of each Player and Content Directory build. BuildHistory.BuildHistoryLimit sets the maximum number of builds to retain. When a new build pushes the count over the limit, the oldest entries are deleted. Set the limit to 0 to disable automatic deletion. You can also invoke the policy manually with BuildHistory.ApplyRetentionPolicy.

Build lifecycle

For Player builds, BuildPlayerProcessor.PrepareForBuild runs before the Player build is added to the history. This allows any content builds triggered during that callback to appear in the history before the Player build itself, resulting in a chronological ordering.

Unity adds a build to the history early in the build process (but after BuildPlayerProcessor.PrepareForBuild) and sets the result to BuildResult.Pending. If the Editor process terminates during a build, the build remains in the history with its initial Pending result.

Some BuildHistory methods, for example BuildHistory.TryGetBuildReportDirectory and BuildHistory.TryGetFilePath, are available for use in the IPreprocessBuildWithReport and IPostprocessBuildWithReport build callbacks.

When the build completes, the BuildReportSummary is updated with the final result (BuildResult.Succeeded, BuildResult.Failed, or BuildResult.Cancelled).

Additional resources: BuildReportSummary, BuildReport

using System;
using System.Text;
using UnityEditor;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
using UnityEngine;

/// <summary> /// Example showing how to scan build history and generate a statistics report. /// </summary> public class BuildHistoryStatsExample { [MenuItem("Example/BuildHistory/Print Build Statistics")] static public void PrintBuildStatistics() { int buildCount = BuildHistory.GetBuildCount();

if (buildCount == 0) { Debug.Log("No builds found in build history."); return; }

// Collect statistics by scanning the summary of all builds long totalTimeMs = 0; int succeededCount = 0;

GUID[] allBuilds = BuildHistory.GetAllBuilds(); foreach (var buildGuid in allBuilds) { BuildReportSummary summary = BuildHistory.GetBuildSummary(buildGuid); totalTimeMs += summary.TotalTimeMs; if (summary.BuildResult == BuildResult.Succeeded) succeededCount++; }

var sb = new StringBuilder(); sb.AppendLine($"=== Build History Statistics ==="); sb.AppendLine($"Total Builds: {buildCount}");

double successRate = (double)succeededCount / buildCount * 100; sb.AppendLine($" Success rate: {successRate}%");

TimeSpan totalTime = TimeSpan.FromMilliseconds(totalTimeMs); sb.AppendLine($"Total Build Time: {totalTime:g}"); TimeSpan averageTime = TimeSpan.FromMilliseconds(totalTimeMs / buildCount); sb.AppendLine($"Average Build Time: {averageTime:g}");

Debug.Log(sb.ToString()); } }

Static Properties

Property Description
BuildHistoryDirectory Gets or sets the path where the build history will be stored.
BuildHistoryLimit Maximum number of builds to retain in the build history.
DefaultRootDirectory The default build history root directory path, regardless of the current build history directory.
LatestBuildReportDirectory Returns the build report directory of the most recent build.

Static Methods

Method Description
ApplyRetentionPolicy Deletes the oldest builds in the build history so that no more than BuildHistory.BuildHistoryLimit remain.
DeleteHistory Deletes all recorded build history.
GetAllBuilds Returns the session GUIDs for all builds in the build history.
GetBuildCount Gets the total number of builds in the build history.
GetBuildSummary Gets the build summary for a specific build.
GetRevision Gets the current revision number of the build history.
LoadBuildReport Loads the BuildReport for a specific build from its metadata folder.
Refresh Updates the BuildHistory incrementally, detecting build directories that have been added or removed on disk.
RefreshFull Performs a full reload of the BuildHistory from disk, discarding all cached state.
TryGetBuildReportDirectory Attempts to get the build report directory for a specific build.
TryGetBuildSummaryForManifestHash Attempts to get the build summary for the most recent build that produced a specific manifest hash.
TryGetBuildSummaryForOutputPath Attempts to get the build summary for the most recent build that was made to a specific output path.
TryGetFilePath Attempts to get the path to a specific file within a build's metadata folder.
TryGetLatestBuild Attempts to get the GUID of the most recent build.