Skip to content

Refactor and fix UnityVersion __getitem__#365

Open
dv1x3r wants to merge 2 commits intoK0lb3:masterfrom
dv1x3r:unityversion
Open

Refactor and fix UnityVersion __getitem__#365
dv1x3r wants to merge 2 commits intoK0lb3:masterfrom
dv1x3r:unityversion

Conversation

@dv1x3r
Copy link

@dv1x3r dv1x3r commented Feb 16, 2026

I encountered an issue exporting meshes from a bundle with UnityVersion 5.3p6.

Sample: bundle_5.3p6.zip

Using the following minimal example:

for obj in env.objects:    
    if obj.type.name == "Mesh":
        data = obj.parse_as_object()
        filename = data.m_Name+".obj"
        file_path = os.path.join(export_path, env.file.name, "models", filename)
        with open(file_path, "wt", newline="") as f:
            f.write(data.export())

I get this error:

File ~/.venv/lib/python3.13/site-packages/UnityPy/helpers/MeshHelper.py:165, in MeshHandler.process(self)
    159 if mesh.m_Use16BitIndices is not None:
    160     self.m_Use16BitIndices = bool(mesh.m_Use16BitIndices)
    161 elif (
    162     self.version >= (2017, 4)
    163     or
    164     # version == (2017, 3, 1) & patched - px string
--> 165     self.version[:2] == (2017, 3)
    166     and mesh.m_MeshCompression == 0
    167 ):
    168     self.m_Use16BitIndices = mesh.m_IndexFormat == 0
    169 self.copy_from_mesh()

File ~/.venv/lib/python3.13/site-packages/UnityPy/helpers/UnityVersion.py:91, in UnityVersion.__getitem__(self, idx)
     89 elif idx == 4:
     90     return self.type_number
---> 91 raise IndexError("Invalid UnityVersion index")

IndexError: Invalid UnityVersion index

The current UnityVersion.__getitem__ implementation does not support slicing, and always raises index error.

In this PR I did not change the (2017, 3) condition (I think it would still be better to add explicit parentheses because of the mixed and and or conditions) and instead added slice support.

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