Unity Build Pipeline

作者 gamedev-skillsd4b0e35550c5无许可证1.3K 个星标收录于 2026年10月8日更新于 2026年10月8日仓库11天前更新

Build and ship Unity 6.3 LTS players: build settings and scenes, player/quality settings, the IL2CPP vs Mono scripting backend, managed code stripping, scripted BuildPipeline.BuildPlayer, and CI/headless builds. Use when configuring or automating a build, choosing a scripting backend, shrinking build size, or when the user mentions Unity build, player settings, IL2CPP, code stripping, or Addressables.

AI 生成的概览

指导配置、编写脚本并自动化 Unity 6.3 LTS 播放器构建,涵盖脚本后端、代码剥离与无头 CI 构建。

功能
说明如何设置 Unity 播放器构建:场景列表、平台目标、Mono 与 IL2CPP 脚本后端、使用 link.xml 的托管代码剥离,以及通过 BuildPipeline.BuildPlayer 编写脚本构建并检查 BuildReport 结果。还介绍使用 batchmode 和退出码的无头 CI 调用方式,以及常见构建陷阱,例如场景缺失、反射代码被剥离和 Addressables 内容过期。参考文件包含更完整的多平台 CI 构建脚本。
适用场景
适用于配置或自动化 Unity 构建、选择脚本后端、通过托管剥离减小构建体积,或接入无头/CI 构建时。适合具有 EditorBuildSettings.asset 或已有 CI 构建脚本的项目。
运行要求
Unity 6.3 LTS(6000.3)编辑器和一个 Unity 项目;IL2CPP 构建需要平台的 C++ 工具链(例如 Windows 生成工具或 Android NDK)。该技能不附带脚本,仅为说明文档加一份参考文档。

Unity Build Pipeline

Configure, script, and automate Unity 6.3 LTS player builds: scenes, platform target, scripting backend, stripping, and headless/CI builds. Targets Unity 6.3 LTS (6000.3).

When to use

  • Use when setting up Build Settings/Profiles, choosing a platform and scripting backend (Mono vs IL2CPP), reducing build size with managed stripping, scripting a repeatable build with BuildPipeline.BuildPlayer, or wiring a CI/headless build.
  • Use when the project has ProjectSettings/EditorBuildSettings.asset or a CI build script.

When not to use: authoring a CI service config end-to-end is DevOps; this skill covers the Unity-side build API and settings. Console/platform certification specifics are platform-NDA territory. Storefront submission → steam-publish / itch-publish.

Core workflow

  1. List the scenes to build (File → Build Profiles/Settings → Scene List, or EditorBuildSettings.scenes). Only listed, enabled scenes ship; scene 0 is the start scene.
  2. Pick the platform target and switch the active build target if needed (BuildTarget / EditorUserBuildSettings).
  3. Choose the scripting backend (Player Settings): Mono (fast iteration, desktop) vs IL2CPP (AOT C++; required for many platforms, better perf, harder to reverse). IL2CPP needs the platform's C++ toolchain installed. (Forward note: Unity is developing a CoreCLR backend as a modern .NET runtime successor to Mono, but it is experimental, desktop-only, and not production-ready as of Unity 6.7 — so for 6.3 LTS the choice stays Mono vs IL2CPP.)
  4. Tune size/perf: set Managed Stripping Level (Disabled → Minimal → Low → Medium → High) and protect reflection-only code with a link.xml. Set Quality Settings per platform.
  5. Script the build with BuildPipeline.BuildPlayer(BuildPlayerOptions) and inspect the returned BuildReport — a non-Succeeded result must fail your pipeline.
  6. Run headless for CI with -batchmode -quit -executeMethod, and check the exit code.
  7. Verify the actual output runs (launch the player), not just that the build returned without throwing.

Patterns

1. Scripted build with a result check

csharp
using UnityEditor;using UnityEditor.Build.Reporting;using UnityEngine;
public static class BuildScript{    [MenuItem("Build/Windows x64")]    public static void BuildWindows()    {        var options = new BuildPlayerOptions        {            scenes = new[] { "Assets/Scenes/Main.unity", "Assets/Scenes/Level1.unity" },            locationPathName = "Builds/Windows/Game.exe",            target = BuildTarget.StandaloneWindows64,            options = BuildOptions.None,            // add BuildOptions.Development for a dev build        };
        BuildReport report = BuildPipeline.BuildPlayer(options);        BuildSummary summary = report.summary;
        if (summary.result != BuildResult.Succeeded)            throw new System.Exception($"Build failed: {summary.totalErrors} errors");        Debug.Log($"Build OK: {summary.totalSize} bytes in {summary.totalTime}");    }}

2. Headless / CI invocation

bash
# Exit code is 0 on success; -quit ensures the editor closes; -nographics for build servers.Unity -batchmode -quit -nographics \  -projectPath "/path/to/Project" \  -executeMethod BuildScript.BuildWindows \  -logFile -

3. Protect stripped code with link.xml

xml
<!-- Assets/link.xml — keep types the linker can't see are used (reflection, JSON, plugins). --><linker>  <assembly fullname="MyGameRuntime" preserve="all"/></linker>

Pitfalls

  • A scene loads in the Editor but is missing in the build — it isn't in the Build Settings scene list (or is disabled). SceneManager.LoadScene only sees listed scenes.
  • IL2CPP build fails on a fresh machine — the platform C++ toolchain (e.g. Windows build tools, Android NDK) isn't installed. Mono has no such requirement.
  • MissingMethodException/TypeLoadException only in the build — managed stripping removed reflection-only code. Lower the stripping level or add a link.xml preserve entry.
  • Treating "BuildPlayer returned" as success — always check BuildReport.summary.result; it can return with errors.
  • Addressables content is stale/missing — Addressables (com.unity.addressables) need a separate content build (Build → Addressables) and a profile pointing at the right load path; a player build alone doesn't rebuild them.
  • Shipping a Development build — BuildOptions.Development enables the profiler/debugging and is slower; use BuildOptions.None for release.

References

  • For a complete multi-platform CI build script (target switching, version stamping, argument parsing, exit codes) and an Addressables content-build call, read references/ci-build-script.md.
  • Primary docs: ScriptReference/BuildPipeline.BuildPlayer, Unity Manual build sections (player settings, managed code stripping). For the forward-looking CoreCLR backend, see the experimental note at https://docs.unity3d.com/6000.7/Documentation/Manual/scripting-backends-coreclr.html.

Related skills

  • steam-publish / itch-publish — distributing the player you just built.
  • unity-csharp-scripting — editor scripting conventions used by build scripts.

来源与署名

来源:gamedev-skills/awesome-gamedev-agent-skills位于skills/unity/unity-build-pipeline提交d4b0e35

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架