A Unity asset extractor for Python based on AssetStudio that supports extraction, editing, and manipulation of Unity game assets.
npx @tessl/cli install tessl/pypi-unitypy@1.23.0A comprehensive Python library for extracting, editing, and manipulating Unity game assets. Built on AssetStudio, UnityPy provides programmatic access to Unity asset files, enabling developers to extract textures, sprites, audio clips, meshes, and other game resources. The library supports both extraction and modification of Unity assets through their native typetree structures.
pip install UnityPyimport UnityPyCommon aliases:
# Main Environment class for loading assets
from UnityPy import Environment
# Alternative load function (same as Environment)
env = UnityPy.load("path/to/assets")For asset decryption:
from UnityPy import set_assetbundle_decrypt_keyFor configuration:
import UnityPy.configimport UnityPy
# Load Unity asset files or directories
env = UnityPy.load("path/to/unity/assets")
# Alternative methods
env = UnityPy.Environment("path/to/asset.bundle")
env = UnityPy.load("path/to/folder/", "specific_file.assets")
# Iterate through all objects in loaded files
for obj in env.objects:
# Check object type
if obj.type.name == "Texture2D":
# Read the object as a Texture2D
texture = obj.read()
# Access properties
print(f"Texture: {texture.m_Name}")
print(f"Format: {texture.m_TextureFormat}")
print(f"Size: {texture.m_Width}x{texture.m_Height}")
# Export to standard format
texture.image.save("exported_texture.png")
elif obj.type.name == "AudioClip":
# Read and export audio
audio = obj.read()
for name, data in audio.samples.items():
with open(f"exported_{name}.wav", "wb") as f:
f.write(data)
# Save modified assets
env.save()Asset modification example:
import UnityPy
env = UnityPy.load("path/to/assets")
for obj in env.objects:
if obj.type.name == "Texture2D":
texture = obj.read()
# Method 1: Modify via parsed class
texture.m_Name = "modified_texture"
texture.save() # Save changes to object
# Method 2: Modify via raw dictionary
raw_data = obj.read_typetree()
raw_data["m_Name"] = "modified_via_dict"
obj.save_typetree(raw_data)
# Save changes
env.save(pack="lz4", out_path="modified_assets/")UnityPy follows Unity's internal asset structure and provides multiple layers of abstraction:
The library supports both high-level parsed object access and low-level typetree manipulation, providing flexibility for different use cases from simple asset extraction to complex asset modification workflows.
Core functionality for loading Unity asset files, directories, and compressed bundles. The Environment class serves as the primary interface for managing multiple asset files and provides unified access to all contained objects.
class Environment:
def __init__(self, *args, fs=None, path=None): ...
def load_file(self, file, parent=None, name=None, is_dependency=False): ...
def load_folder(self, path: str): ...
def load_files(self, files: List[str]): ...
def save(self, pack="none", out_path="output"): ...
@property
def objects(self) -> List[ObjectReader]: ...
@property
def container(self): ...
def load(*args, **kwargs) -> Environment: ...
def set_assetbundle_decrypt_key(key): ...Complete collection of Unity asset types including textures, audio, meshes, shaders, and game objects. Each class provides typed access to Unity's native data structures with methods for reading, modifying, and exporting assets.
class ObjectReader:
@property
def type(self) -> ClassIDType: ...
@property
def path_id(self) -> int: ...
@property
def class_id(self) -> int: ...
def read(self, check_read: bool = True) -> T: ...
def read_typetree(self, nodes: Optional[NodeInput] = None, wrap: bool = False, check_read: bool = True) -> Union[dict, T]: ...
def save_typetree(self, tree: Union[dict, T], nodes: Optional[NodeInput] = None, writer: Optional[EndianBinaryWriter] = None): ...
def get_raw_data(self) -> bytes: ...
def set_raw_data(self, data: bytes): ...
class Texture2D(Object):
m_Name: str
m_Width: int
m_Height: int
m_TextureFormat: int
image_data: bytes
@property
def image(self) -> Image.Image: ...
@image.setter
def image(self, img: Union[Image.Image, str, BinaryIO]): ...
class AudioClip(Object):
m_Name: str
m_CompressionFormat: int
@property
def samples(self) -> Dict[str, bytes]: ...
@property
def extension(self) -> str: ...
class Mesh(Object):
m_Name: str
@property
def vertices(self) -> List[Vector3f]: ...
@property
def triangles(self) -> List[int]: ...
def export(self) -> str: ...
class Sprite(Object):
m_Name: str
@property
def image(self) -> Image.Image: ...
@property
def texture(self) -> PPtr[Texture2D]: ...Support for Unity's various file formats including serialized assets, compressed bundles, and web-optimized files. Each file type provides specialized loading, parsing, and compression handling.
class SerializedFile:
@property
def objects(self): ...
def save(self, packer="none"): ...
class BundleFile:
@property
def files(self): ...
def save(self): ...
class WebFile:
@property
def files(self): ...
def save(self): ...Comprehensive export capabilities for converting Unity assets to standard formats. Includes format conversion, compression options, and platform-specific optimizations for textures, audio, meshes, and other asset types.
class Texture2DConverter:
def export_PIL(texture): ...
def export_bytes(texture, format): ...
class AudioClipConverter:
def export_wav(audio_clip): ...
def export_ogg(audio_clip): ...
class MeshExporter:
def export_obj(mesh): ...
def export_ply(mesh): ...
class SpriteHelper:
def export_sprite(sprite): ...Complete set of Unity enumerations and constants including texture formats, audio types, build targets, and other Unity-specific identifiers used throughout the asset system.
class TextureFormat(Enum): ...
class AudioType(Enum): ...
class ClassIDType(Enum): ...
class BuildTarget(Enum): ...
class GraphicsFormat(Enum): ...Low-level binary data reading and writing with endianness support, enabling direct manipulation of Unity's binary asset formats and custom data structures.
class EndianBinaryReader:
def read_int(self): ...
def read_string(self): ...
def read_bytes(self, count): ...
class EndianBinaryWriter:
def write_int(self, value): ...
def write_string(self, value): ...
def write_bytes(self, data): ...Global configuration options for controlling UnityPy behavior including Unity version fallbacks and performance optimizations.
# Configuration variables
FALLBACK_UNITY_VERSION: Optional[str] # Default Unity version when not specified
SERIALIZED_FILE_PARSE_TYPETREE: bool # Control typetree parsing for performance
def get_fallback_version() -> str: ... # Get configured fallback version with validationAccess via UnityPy.config module for advanced performance tuning and Unity version handling.