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

BuildHistory.DeleteHistory

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

Declaration

public static int DeleteHistory();

Returns

int The number of build metadata directories successfully deleted.

Description

Deletes all recorded build history.


Declaration

public static int DeleteHistory(GUID[] buildSessionGuids);

Parameters

Parameter Description
buildSessionGuids The unique session GUIDs of the builds to delete from the history.

Returns

int The number of builds successfully deleted.

Description

Deletes specific build metadata directories.

using System;
using System.Collections.Generic;
using System.Globalization;
using UnityEditor;
using UnityEditor.Build;
using UnityEngine;

public class DeleteOldBuildsExample { [MenuItem("Example/BuildHistory/Delete Builds Older Than 48 Hours")] static public void DeleteOldBuilds() { TimeSpan maxAge = TimeSpan.FromHours(48); DateTime cutoffTime = DateTime.UtcNow - maxAge;

var buildsToDelete = new List<GUID>();

GUID[] allBuilds = BuildHistory.GetAllBuilds(); foreach (var buildGuid in allBuilds) { try { BuildReportSummary summary = BuildHistory.GetBuildSummary(buildGuid);

// BuildStartedAt is an ISO 8601 UTC timestamp if (DateTime.TryParse(summary.BuildStartedAt, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind, out DateTime buildStartTime)) { if (buildStartTime.ToUniversalTime() < cutoffTime) { buildsToDelete.Add(buildGuid); } } } catch (Exception e) { Debug.LogWarning($"Failed to get summary for build {buildGuid}: {e.Message}"); } }

if (buildsToDelete.Count == 0) { Debug.Log($"No builds older than {maxAge.TotalHours} hours found."); return; } int deletedCount = BuildHistory.DeleteHistory(buildsToDelete.ToArray()); Debug.Log($"Deleted {deletedCount} builds older than {maxAge.TotalHours} hours."); } }