Skip to content

Commit 34f88e2

Browse files
committed
fix(sprite): verify the sprites exist before slice_sheet reports them
The previous commit closes the one reproducible way Unity accepts a grid and emits nothing. It is not the only way: Unity reports an import that generates no sprite through the console, not through an exception or a return value, so any future cause lands as the same silent success. Counting the sprites actually on the asset answers that without having to enumerate the causes. No dedicated test: the only trigger that reproduces on demand is the NPOT path, and the commit before this one fixes that path rather than leaving it available to assert on. Every existing slice test asserts the sprite count through the Slice fixture helper, so the invariant this guard enforces is already the one they measure.
1 parent 7b61eba commit 34f88e2

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

MCPForUnity/Editor/Tools/Sprite2D/SpriteImportSetup.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,18 @@ private static object SliceConverted(JObject @params, SpriteDiagnosticBuilder di
312312
EditorUtility.SetDirty(importer);
313313
importer.SaveAndReimport();
314314

315+
// Unity can accept every SpriteMetaData entry and still emit no sprite for it, and
316+
// it says so in the console rather than throwing. NPOT scaling was one such path
317+
// and is closed above; an import that fails for any other reason would report the
318+
// same success over an empty asset. Counting what is actually on the asset is the
319+
// only answer that does not depend on knowing the causes in advance.
320+
int generated = AssetDatabase.LoadAllAssetsAtPath(path).OfType<Sprite>().Count();
321+
if (generated != totalFrames)
322+
return diagnostics.Fail("SLICE_NOT_GENERATED",
323+
$"Unity accepted a {cols}x{rows} grid but generated {generated} of {totalFrames} sprites for '{path}'.",
324+
"Check the Unity console for the import error",
325+
"Confirm the texture's import settings allow sprite generation");
326+
315327
return new
316328
{
317329
success = true,

0 commit comments

Comments
 (0)