Home / Unity / U05

Unity error: IndexOutOfRangeException: Index was outside the bounds of the array. / UnityEngine.AddressableAssets.Utility.AssetReferenceUtilities.GetAtlasSpritesAndPackables (UnityEngine.U2D.SpriteAtlas& atlas) (at ./Library/PackageCache/com.unity.addressables/Runtime/Utility/AssetReferenceUtilities.cs:30) — cause and fix

In Addressables 2.x, a SubObject is selected for the AssetReferenceAtlasedSprite field in

ID
U05
Engine
Unity
Verification
原文命中(抓取页面)
Frequency
论坛点赞=0

Original message (verbatim)

IndexOutOfRangeException: Index was outside the bounds of the array. / UnityEngine.AddressableAssets.Utility.AssetReferenceUtilities.GetAtlasSpritesAndPackables (UnityEngine.U2D.SpriteAtlas& atlas) (at ./Library/PackageCache/com.unity.addressables/Runtime/Utility/AssetReferenceUtilities.cs:30)

Placeholders such as %s / %d are kept verbatim from the engine source and are not replaced with concrete values.

Trigger

In Addressables 2.x, a SubObject is selected for the AssetReferenceAtlasedSprite field in the Inspector; the SpriteAtlas Objects for Packing contains folders rather than individual sprites, and the throw occurs when atlas.spriteCount and atlas.GetPackables() return mismatched lengths; reproducible on Unity 6000.0.27f1 + Addressables 2.2.2/2.3.1. Multi-line stack.

Typical cause

GetPackables() keeps folder objects without expanding them into sprites; the loop reads atlasPackables[i] by atlas.spriteCount, and the index exceeds the array returned by GetPackables, triggering IndexOutOfRangeException.

Step-by-step fix

  1. Put sprites directly into the atlas Objects for Packing (expand folders before packing); do not use a folder as a packable.
  2. Upgrade the Addressables package.
  3. At runtime use SubObjectName to select the sub-object instead of the editor selector path.

Source links

Per-entry sources and capture date are listed at /sources#U05.

Related errors

Related Unity errors

Need an offline quick-reference checklist?

Atlas error library Pro pack: 123 error references (110 single + 13 merged) plus a quick-fix guide, $19 one-time purchase, delivered as electronic files.

View Pro pack / order

Back to the all-errors index Checkout and buy the Pro pack — $19.00