Skip to content

Preserve read metadata bytes on rewrite#142

Open
InternetRando1 wants to merge 1 commit intoatenfyr:masterfrom
InternetRando1:fix/lost-metadata-bytes
Open

Preserve read metadata bytes on rewrite#142
InternetRando1 wants to merge 1 commit intoatenfyr:masterfrom
InternetRando1:fix/lost-metadata-bytes

Conversation

@InternetRando1
Copy link
Copy Markdown

Fixes loss of MetaData section when roundtripping UE5.4+ assets

Steps to reproduce:

  1. Open any .uasset created by UE5.4+ (ObjectVersionUE5 >= METADATA_SERIALIZATION_OFFSET)
  2. Roundtrip it: new UAsset(path, engineVersion).Write(outputPath)
  3. Compare file sizes — output is smaller (e.g. -53 bytes for attached test Material based on Epic tutorial M_Screen_Damage.zip)
  4. Open the roundtripped file in Unreal Editor — it fails to load

Root cause:
UAsset.ReadHeader() reads MetaDataOffset (introduced in UE5.4), but the corresponding
bytes are never read or preserved. During write:

  • The original MetaDataOffset is written back into the header
  • No MetaData section is emitted

This causes:

  • The MetaData section to be dropped
  • File size to shrink
  • MetaDataOffset to point to an invalid location

Observed impact:
For a UE5.7 Material asset, this removes 53 bytes of build dependency hash data.
The resulting file is rejected by Unreal Editor.

What the MetaData section contains:
Raw bytes between MetaDataOffset and ImportOffset.
In UE5.7 this includes package build dependency metadata (hash strings).
This format is currently not parsed by UAssetAPI.

Fix:
Preserve the MetaData section as raw bytes (passthrough):

  • Add field: byte[] MetaDataBytes
  • Read: capture bytes between MetaDataOffset and ImportOffset
  • Write: emit MetaDataBytes before Imports and update MetaDataOffset

This preserves correctness without introducing format-specific parsing.
Future work could deserialize this section if needed.

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.

1 participant