npx skills add ...
npx skills add unity-technologies/skills --skill manage-sprite-atlas
Manage SpriteAtlas using prebuild pipeline with IPreprocessBuildWithReport (DEFAULT approach). Use it to configure master atlases, variant atlases, texture settings, packing settings, and platform-specific configurations. Use when the user asks about creating sprite atlases, optimizing sprites, configuring atlas settings, adding sprites to atlases, creating variant atlases, implementing automated atlas generation, or runtime sprite atlas access. Always use prebuild approach unless user explicitly requests manual authoring.
npx skills add unity-technologies/skills --skill manage-sprite-atlas
Provides editor-safe procedural knowledge for scripting atlases in Unity projects. V2 enforces strict separation between editor authoring and runtime access.
โ ๏ธ Critical V2 Principle:
SpriteAtlasis runtime-only.SpriteAtlasAssetis editor-only. Never mix contexts. Always use V2.
ALWAYS perform these checks and ask these questions BEFORE generating any code:
This skill ships working C# under resources/, and the atlas code that goes wrong is almost always
code written without reading it first. Open the files for the path you are taking, then write.
| Taking this path | Read first |
|---|---|
| Any atlas work at all | resources/authoringvsruntime.cs, references/common-errors.md |
| Prebuild generation (the default) | resources/spriteatlasprebuildgenerator.cs, resources/enablespritepacking.cs, resources/savespriteatlasasset.cs |
| Option B, Addressables late-binding | resources/buildaddressablespostprocess.cs, resources/spriteatlaslatebinding.cs, resources/handlelatebinding.cs |
| Anything that might use an older API | resources/deprecatedmethods.cs, resources/dontscriptspriteatlasineditor.cs, resources/dontpackinruntimebuilds.cs |
resources/ holds 38 files in all, covering custom packers, variants, platform settings, and
runtime access. Browse the directory when your task is not in the table above rather than inventing
an approach. Reaching for the API from memory instead of reading these is the single most common
cause of an atlas that imports cleanly and then does nothing at runtime.
BEFORE generating any code, scan the project for existing SpriteAtlas scripts generated by this skill.
Search for files containing the identifier: // [UNITY-SKILL:SPRITEATLAS]
If existing scripts are found, ALWAYS ask the user with this format:
"I found existing SpriteAtlas scripts in your project:
Prebuild Generator:
Assets/Editor/SpriteAtlas/SpriteAtlasPrebuildGenerator.csAddressables Builder:
Assets/Editor/SpriteAtlas/BuildAddressablesPostprocess.csRuntime Loader:
Assets/Scripts/SpriteAtlas/SpriteAtlasLateBinding.csWhat would you like to do?"
Then present options:
Option A: Update existing scripts (Recommended if requirements changed)
Option B: Create new scripts with different names
Option C: Abort (keep existing unchanged)
User Choice Handling:
Ask: "How do you want to deliver the sprite atlases?"
Option A: Built-in Data (Immediate Loading)
includeInBuild = trueOption B: Late-Binding via Addressables (On-Demand Loading)
includeInBuild = false| Use Case | Recommended |
|---|---|
| Core UI sprites that are always visible | Option A: Built-in |
| Tutorial or onboarding sprites | Option A: Built-in |
| Level-specific sprites (100+ levels) | Option B: Addressables |
| DLC or seasonal content | Option B: Addressables |
| Localized UI sprites (multiple languages) | Option B: Addressables |
| Character skins or cosmetics | Option B: Addressables |
Enable Sprite Packer mode before creating atlases, then read the setting back and confirm it took.
Use the code in resources/enablespritepacking.cs; it sets
EditorSettings.spritePackerMode and configures the importer's packing settings.
This is the step that decides whether the atlas you produce is real. Disabled is the zero value of
SpritePackerMode, so any project where nobody has set it carries packing Disabled, and an atlas
created while it is Disabled still imports, still shows up as an asset, and still looks finished, but
can never pack. Unity says so in the Inspector: "Sprite Atlas packing is disabled". Nothing else in
the workflow fails, so an atlas shipped this way reads as a success. Do not assume a project is
already configured: read the value.
So do not treat "I set it" as done. After setting it, read EditorSettings.spritePackerMode back,
confirm it is not Disabled, and report the value you actually read. If you cannot read it back,
say so rather than assuming the write landed.
DO NOT edit meta files DIRECTLY.
ALWAYS use IPreprocessBuildWithReport to automatically generate or update SpriteAtlases during the build pipeline. This is the DEFAULT and REQUIRED approach unless the user EXPLICITLY requests manual authoring.
NEVER create scripts with [MenuItem] attributes for atlas generation unless explicitly requested. The prebuild approach eliminates the need for manual clicks. Only use manual authoring for: Hand-optimized layouts, specific sprite arrangements, or editor preview requirements. See Advanced: Manual Authoring.
ONLY add sprites from the project's Assets folder. NEVER add sprites from Unity built-in assets, packages, or external locations. Unity built-in assets cannot be packed into SpriteAtlas, and package assets may cause import/dependency issues.
| Context | Component | Purpose | Allowed Usage |
|---|---|---|---|
| Editor Authoring | SpriteAtlasAsset | Add/remove sprites/folders; store metadata | โ Editor scripts only |
| Editor Settings | SpriteAtlasImporter | Configure texture, packing, platform settings | โ Editor scripts only |
| Editor Packing | SpriteAtlasUtility.PackAtlases() | Optional editor preview packing (not for build) | โ ๏ธ Only for preview; atlases auto-pack at build |
| Runtime | SpriteAtlas | Query packed sprites (read-only) | โ Runtime scripts only |
| Runtime Loading | SpriteAtlasManager | Dynamic loading callbacks | โ Runtime scripts only |
| โ Invalid Pattern | โ Correct Pattern |
|---|---|
new SpriteAtlas() in editor code | Use SpriteAtlasAsset + SpriteAtlasImporter |
AssetDatabase.LoadAssetAtPath<SpriteAtlas>(...) in editor | Use SpriteAtlasAsset.Load(...) |
SpriteAtlasAsset.GetPackables() in editor | Use SpriteAtlas.GetPackables() |
Modifying SpriteAtlas in editor scripts | Modify SpriteAtlasAsset โ reimport โ use SpriteAtlasImporter |
| Create variants from original packable objects (sprites/folders) | Creating variants from a Master runtime SpriteAtlas |
NEVER script against SpriteAtlas in editor code โ it is only for runtime use in V2 except for GetPackables.
๐จ IMPORTANT: This workflow is shown for reference only. ALWAYS implement this inside
IPreprocessBuildWithReport.OnPreprocessBuild()rather than in manual scripts. See Quick Start.
This is the PRIMARY and DEFAULT way to create SpriteAtlases. Implement IPreprocessBuildWithReport to automatically generate or update SpriteAtlases before each build based on categorization rules. No manual menu clicks required.
Step 1: Ask User for Delivery Mechanism
Before generating code, ask: "How do you want to deliver the sprite atlases: (A) Built-in data or (B) Late-binding via Addressables?"
Step 2: Create Prebuild Script
Create this script in an Editor folder. Customize based on user's delivery choice:
Built-in Data (Immediate Loading)
๐จ CRITICAL ENFORCEMENT: When user chooses Addressables, you MUST generate ALL THREE scripts below. Never generate just one or two - all three are required for Addressables delivery to work.
Required Scripts (ALL THREE MANDATORY):
See references/addressables-delivery.md for complete implementation.
Step 3: Customize Categorization Rules
Edit the OnPreprocessBuild method to match your project's sprite organization. Choose one or combine multiple strategies:
| Strategy | When to Use | Implementation |
|---|---|---|
| Folder-based | Sprites organized by folder structure | GenerateAtlasByFolder("Assets/Art/UI", "Assets/Atlases/UI.spriteatlasv2") |
| Naming convention | Sprites follow naming patterns | GenerateAtlasByNaming("Assets/Art", "icon_", "Assets/Atlases/Icons.spriteatlasv2") |
| Asset labels | Sprites tagged with labels | |
| Scene-based | Sprites used in specific scenes | Query scene references |
Step 4: Build Your Project
Atlases are automatically generated/updated during build. No manual menu clicks required. This is why prebuild is the default approach.
For Built-in Data (Option A):
For Addressables (Option B) - Additional Required Steps:
You MUST generate THREE scripts (not just one):
The build process will:
By Folder Structure:
By Naming Convention:
Generate variant atlases for different resolutions.
โ ๏ธ WARNING: Manual authoring is NOT the default approach. Only use these patterns when the user EXPLICITLY requests manual control or editor preview during development.
๐จ DEFAULT APPROACH: Use prebuild generation with
IPreprocessBuildWithReportinstead. See Quick Start.
Manual authoring is appropriate ONLY for:
DO NOT use manual authoring when:
For complete manual authoring patterns including master atlas creation, variant creation, and runtime loading, see references/manual-authoring.md.
[UNITY-SKILL:SPRITEATLAS] identifier and prompt user to update or create newEditorSettings.spritePackerMode = SpritePackerMode.SpriteAtlasV2 in prebuild scriptIPreprocessBuildWithReport as the DEFAULT approach for creating atlasesIPostprocessBuildWithReport to build Addressables contentSpriteAtlasManager)true for built-in data, false for AddressablesSpriteAtlasAsset โ Save โ Import โ Configure via SpriteAtlasImporter โ SaveAndReimport()SpriteAtlas in editor code โ except SpriteAtlas.GetPackables() instance method on a loaded runtime atlasSetMasterAtlas(SpriteAtlas) with runtime instance loaded via AssetDatabase.LoadAssetAtPath<SpriteAtlas>()format = TextureImporterFormat.ASTC_6x6 directly (no cast).spriteatlasv2 (not .spriteatlas)SpriteAtlasUtility.PackAtlases() is optional: Only for editor preview; build-time packing is automaticFor common errors and invalid patterns, see references/common-errors.md.
ScriptablePacker implementationEditor Scripts:
Runtime Scripts:
GenerateAtlasByFolder("Assets/Art/UI/Buttons", "Assets/Atlases/UI_Buttons.spriteatlasv2");
GenerateAtlasByFolder("Assets/Art/UI/Icons", "Assets/Atlases/UI_Icons.spriteatlasv2");
GenerateAtlasByFolder("Assets/Art/Characters/Player", "Assets/Atlases/Player.spriteatlasv2");GenerateAtlasByNaming("Assets/Art", "icon_", "Assets/Atlases/Icons.spriteatlasv2");
GenerateAtlasByNaming("Assets/Art", "bg_", "Assets/Atlases/Backgrounds.spriteatlasv2");using UnityEditor; // AssetImporter, AssetDatabase
using UnityEditor.U2D; // SpriteAtlasAsset, SpriteAtlasImporter, SpriteAtlasUtility
using UnityEngine; // Runtime types (e.g., TextureImporterFormat)
using UnityEngine.U2D; // SpriteAtlasusing UnityEngine; // Core Unity types
using UnityEngine.U2D; // SpriteAtlas, SpriteAtlasManager