Repository navigation
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Code
import os
import UnityPy
def unpack_all_assets(source_folder : str, destination_folder : str):
# iterate over all files in source folder
for root, dirs, files in os.walk(source_folder):
for file_name in files:
# generate file_path
file_path = os.path.join(root, file_name)
# load that file via UnityPy.load
env = UnityPy.load(file_path)
# iterate over internal objects
for obj in env.objects:
# process specific object types
if obj.type.name in ["Texture2D", "Sprite"]:
# parse the object data
data = obj.read()
# create destination path
dest = os.path.join(destination_folder, data.name)
# make sure that the extension is correct
# you probably only want to do so with images/textures
dest, ext = os.path.splitext(dest)
dest = dest + ".png"
img = data.image
img.save(dest)
# alternative way which keeps the original path
for path,obj in env.container.items():
if obj.type.name in ["Texture2D", "Sprite"]:
data = obj.read()
# create dest based on original path
dest = os.path.join(destination_folder, *path.split("/"))
# make sure that the dir of that path exists
os.makedirs(os.path.dirname(dest), exist_ok = True)
# correct extension
dest, ext = os.path.splitext(dest)
dest = dest + ".png"
data.image.save(dest)Error
ValueError: 9 is not a valid SpritePackingRotation
Bug
This error is thrown from Pythons enum library because no SpritePackingRotation with value 9 is defined.
To Reproduce
- sadly cannot include because i do not own the copyright
- following data:
- Python 3.7
- UnityPy==1.7.28
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working
Activity
K0lb3 commentedon Jan 24, 2022
Sounds like the issue seems to be with the Sprite object parsing as a packing rotation of 9 is indeed invalid.
See Unity-Technologies/UnityCsReference/Sprites.bindings.cs
Can you check if it's only a specific Sprite that causes the issue or if all Sprites of the game cause that issue?
If all of them cause the issue, can you share the Unity version of the asset as well as the typetree of the Sprite object?
JulianWinter1124 commentedon Jan 24, 2022
There are multiple sprites to fail (most of them actually). It also worked for an older version of the game.
The stated Unity Version in the .ab file is 2020.3.13f1.
K0lb3 commentedon Feb 5, 2022
Looks like 2020,3 (or maybe even earlier) uses more detailed bones than previously.
So far the bones used to be a simple vector of 2 float values, but now they have a class on their own with more details.
UnityPy 1.7.33 should fix the issue, can you please check it?
JulianWinter1124 commentedon Feb 7, 2022
Hey again, I just tested and the same error appears for all files. Also made double sure I am on version 1.7.33.
Also I just noticed there is also an error with 10:
9 is not a valid SpritePackingRotation10 is not a valid SpritePackingRotationThe traceback
Also this page should show the rotations for the specific Unity version: https://github.com/Unity-Technologies/UnityCsReference/blob/2020.3.13f1/Runtime/2D/Common/ScriptBindings/Sprites.bindings.cs (It still does not show 9 nor 10 though)
K0lb3 commentedon Feb 7, 2022
Cough, well, I already referred to the page you mentioned :P
I was a bit sleepy when I checked it two days ago and only fixed another possible problem with Sprites that had nothing to do with this one.
I can't really figure out how to force the Unity Editor to produce a sprite with a specific packing rotation,
so it's kinda hard to figure this out without a sample.
A single sprite with its texture would help a ton.
You could also send it to me by mail to prevent it from appearing in the public.
rudolf.kolbe@ovgu.deJulianWinter1124 commentedon Feb 8, 2022
I sent you a mail with more details. sprite.m_RD.texture.get_raw_data() threw an error
K0lb3 commentedon Feb 8, 2022
Thanks for the mail.
Looks like the problem was related to the SpriteAtlasData that is used by the Sprites.
Starting with Unity 2020.2 secondaryTextures were added, which weren't parsed yet in UnityPy, which in turn let the reader come off the track and read the data wrong.
1.7.34 fixes the problem.
JulianWinter1124 commentedon Feb 8, 2022
it works 🥳
1.7.34 - SpriteAtlasData 2020,2+ added