How to automatically zip your Unity build
Every time you share a build, you zip the folder, rename the ZIP and delete the folders that shouldn't ship. A short editor script can do all of that the moment Unity finishes building.
The short answer
Unity calls any class that implements IPostprocessBuildWithReport right after a build. The report tells you where the build went, so the script can zip that folder with .NET's ZipFile.
1. Add the script
Create a folder called Editor anywhere inside Assets, then add a script called ZipBuildAfterBuilding.cs with this code:
using System.IO;
using System.IO.Compression;
using UnityEditor;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
using UnityEngine;
public class ZipBuildAfterBuilding : IPostprocessBuildWithReport {
public int callbackOrder => 0;
public void OnPostprocessBuild(BuildReport report) {
// On Windows the output path is the .exe, so zip the folder it's in.
// On macOS it's the .app folder, and on WebGL it's the build folder.
string output = report.summary.outputPath;
string buildFolder = Directory.Exists(output) ? output : Path.GetDirectoryName(output);
// Save the ZIP next to the build folder, not inside it
string zipName = $"{PlayerSettings.productName} v{PlayerSettings.bundleVersion} ({report.summary.platform}).zip";
string zipPath = Path.Combine(Path.GetDirectoryName(buildFolder), zipName);
if (File.Exists(zipPath)) {
File.Delete(zipPath);
}
using (ZipArchive zip = ZipFile.Open(zipPath, ZipArchiveMode.Create)) {
foreach (string file in Directory.GetFiles(buildFolder, "*", SearchOption.AllDirectories)) {
string relative = Path.GetRelativePath(buildFolder, file);
// Unity's debug folders say not to ship them
if (relative.Contains("DoNotShip") || relative.Contains("DontShip")) {
continue;
}
zip.CreateEntryFromFile(file, relative.Replace('\\', '/'), System.IO.Compression.CompressionLevel.Optimal);
}
}
Debug.Log($"Zipped build: {zipPath}");
}
}
2. Build as normal
Go to File > Build Profiles (or Build Settings in Unity 2022) and build. When it finishes, the Console shows the path of the new ZIP, sitting next to your build folder and named after your product, version and platform, for example My Game v1.2.0 (StandaloneWindows64).zip.
The product name and version come from Project Settings > Player, so change them there.
Things to watch
Keep the ZIP outside the build folder
If the ZIP is saved inside the folder it's zipping, the next build would zip the old ZIP too. The script above saves it one level up for that reason.
Leave out the "do not ship" folders
Builds that use Burst or IL2CPP add folders such as …_BurstDebugInformation_DoNotShip and …_BackUpThisFolder_ButDontShipItWithYourGame. They hold debug data, not game files, and can be large. The script skips any path containing "DoNotShip" or "DontShip".
Big builds take a moment
Zipping happens inside the build, so Unity stays busy until the ZIP is written. For a faster build, change CompressionLevel.Optimal to CompressionLevel.Fastest.