Skip to content

fix(Texture2DArray): read the layers of streamed texture arrays - #391

Open
nichinichisou0609 wants to merge 1 commit into
K0lb3:masterfrom
nichinichisou0609:fix/texture-without-data
Open

nichinichisou0609 wants to merge 1 commit into
K0lb3:masterfrom
nichinichisou0609:fix/texture-without-data

Conversation

@nichinichisou0609

@nichinichisou0609 nichinichisou0609 commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Texture2DArray.images only read m_StreamData when image_data was None. A streamed array serializes image_data as an empty byte string, so its resource file was never read and every streamed array failed with Texture2D has no image data.

  • Texture2DArray gets a get_image_data() with the same rules as Texture2D.get_image_data(): the inline data if there is any, else the resource named by m_StreamData, else ValueError("No image data found").
  • images decodes the layers with the object reader's platform instead of 0, as Texture2D does.

The Texture2D half of this PR is already on master through #395.

Comment thread UnityPy/export/Texture2DConverter.py Outdated
) -> Image.Image:
"""Converts the given Texture2D object to PIL Image."""
if not texture_2d.m_Width or not texture_2d.m_Height:
return Image.new("RGBA", (0, 0))

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is not necessary, as parse_image_data already does it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed, thanks!

Small heads-up in case it matters: get_image_data() runs before parse_image_data, so a 0x0 texture without data now raises ValueError("No image data found") (same as after #395) instead of returning an empty image. Either is fine for me.

Comment thread tests/test_texture.py Outdated
@@ -0,0 +1,104 @@
from types import SimpleNamespace

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While correct in theory,
the test here is completely engineered on scope,
and might therefore not the real world scenario.

So, please remove it test.
Long term I plan to add a bunch of self made samples covering all directly supported special object classes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, removed it. I attached a small sample below instead, in case it's useful when you set up the sample tests.

Texture2DArray.images only read m_StreamData when image_data was None.
A streamed array serializes image_data as an empty byte string, so the
resource file was never read and every streamed array failed with
"Texture2D has no image data".

Texture2DArray now has get_image_data(), with the same rules as
Texture2D.get_image_data(): the inline data when there is any, else the
resource named by m_StreamData, else a ValueError. images uses it and
decodes the layers with the platform of the object reader instead of
platform 0, as Texture2D does.
@nichinichisou0609 nichinichisou0609 changed the title fix: Texture2D without image data and streamed Texture2DArray fix(Texture2DArray): read the layers of streamed texture arrays Nov 16, 2026
@nichinichisou0609

nichinichisou0609 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor Author

Rebased on master. #395 already covers the Texture2D part, so this PR is now only the Texture2DArray fix, and I've updated the title to match.

I also switched the getattr(self.object_reader, "platform", ...) fallback to plain self.object_reader.platform, since the line above already uses self.object_reader.version.

In case you want a sample for it: the zip has a tiny AssetBundle with one streamed Texture2DArray, built from an empty Unity 2022.3 project (the build script is included). Feel free to ignore it if you'd rather build your own.

unitypy-391-samples.zip

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants