Unity SpriteAtlas V2
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.
🚨 CRITICAL: Required Checks and User Inputs Before Implementation
ALWAYS perform these checks and ask these questions BEFORE generating any code:
Read the shipped resources before writing code (REQUIRED)
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.
0. Check for Existing Scripts (REQUIRED FIRST STEP)
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)
- Regenerates scripts at existing paths
- Preserves file locations
- Updates to latest version
- ⚠️ May overwrite custom modifications
-
Option B: Create new scripts with different names
- Generates alongside existing scripts
- Allows multiple atlas configurations
- Original scripts remain unchanged
- You'll need to specify new names/paths
-
Option C: Abort (keep existing unchanged)
- No code generation
- No changes to project
- Use this if you want to keep current setup
User Choice Handling:
- If A chosen: Regenerate at existing paths, increment version to 2.0.1+
- If B chosen: Ask for new script names (e.g., "SpriteAtlasPrebuild_Custom.cs"), then generate
- If C chosen: Stop immediately, inform user no changes were made
1. Delivery Mechanism (REQUIRED)
Ask: "How do you want to deliver the sprite atlases?"
Option A: Built-in Data (Immediate Loading)
- Atlases are included in the build and loaded immediately
- Set
includeInBuild = true - Suitable for: Core UI, main gameplay sprites, always-needed assets
- Pros: Simple, no additional packages, instant access
- Cons: Increases initial build size, cannot update without new build
Option B: Late-Binding via Addressables (On-Demand Loading)
- Atlases are NOT included in build, loaded on-demand via Addressables
- Set
includeInBuild = false - Create Addressables entries for each atlas
- Add addressable setup as prebuild step
- 🚨 REQUIRED: Build Addressables content as build step
- 🚨 REQUIRED: Create late-binding runtime loader script
- Suitable for: DLC content, optional features, large assets, downloadable content
- Pros: Smaller initial build, can update independently, on-demand loading
- Cons: Requires Addressables package, async loading, network dependency
| 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 |
2. SpritePacker Mode (REQUIRED)
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.
🚨 CRITICAL: Default Approach is Prebuild Generation
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.
❌ DO NOT Create Manual Menu Item Scripts
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.
🚨 CRITICAL: Sprite Source Location Restriction
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.
Critical V2 Architecture
| Context | Component | Purpose | Allowed Usage |
|---|