← Back to Projects

🎮 Unity Image Extractor

UnityPy Python 3.13 PIL/Pillow Batch Processing

Project Category: Individual Project (Personal Productivity Tool)

I built a command-line tool that automates texture extraction from Unity game files. My implementation uses UnityPy to parse proprietary Unity asset bundles, identifies Texture2D and Sprite objects, and converts them to standard PNG format. The tool supports batch processing with recursive directory scanning and maintains organized output structures.

🧰 Technologies & Tools Used

UnityPy

A Python library that reverse-engineers Unity's proprietary asset bundle format (UnityFS). UnityPy reads the binary file structure, parses object type definitions, and extracts asset data without requiring Unity Editor. It handles various Unity versions (5.x - 2022.x) and supports multiple asset types including textures, sprites, audio, and meshes. For this project, I specifically target Texture2D and Sprite objects.

PIL/Pillow

Python Imaging Library (Pillow) handles the image format conversion. UnityPy extracts raw pixel data from Unity's internal texture format, then Pillow converts it to standard PNG with proper color channels (RGB/RGBA). It also handles image metadata like dimensions and compression.

My Batch Processing Architecture

I engineered a recursive directory scanner with the -r flag that traverses folder hierarchies, identifies Unity bundle files by signature detection, and maintains source-to-output directory mapping. This allows processing entire game folders (500+ files) in one command while preserving the original file organization.

🔄 How It Works: Processing Pipeline

1. Input Detection

Accepts Unity3D file or directory path. With -r flag, recursively scans for .unity3d, .bundle, .assets files

2. UnityFS Signature Check

Validates file header for UnityFS magic bytes (0x55 0x6E 0x69 0x74 0x79 0x46 0x53). Skips non-Unity files automatically

3. Bundle Extraction

UnityPy decompresses bundle data (LZ4/LZMA), parses type tree, and loads object containers

4. Asset Scanning

Iterates through all objects, filters for Texture2D and Sprite types, extracts image data and metadata (dimensions, format)

5. PNG Conversion

Pillow converts raw pixel data to PNG format with proper color channels. Maintains transparency (RGBA) for sprites

6. Organized Output

Saves to extracted_images/ directory with structure mirroring source. Example: source/characters/hero.unity3dextracted_images/characters/hero_texture1.png

🔧 My Implementation

Intelligent File Detection

My code automatically identifies Unity bundle files by signature, not extension - handles renamed or obfuscated files

Recursive Directory Processing

I built the -r flag to traverse entire game folders, processing 500+ files while maintaining source organization

Custom Output Paths

My -o parameter allows flexible output destinations, useful for batch processing multiple games to separate folders

CLI Automation Ready

I designed the interface for scripting - no interactive prompts, clean exit codes, perfect for batch files or automated workflows

💻 Usage

Extract from Single File

py unity_image_extractor.py "path\to\file.unity3d"

Extract from Entire Folder (Recursive)

py unity_image_extractor.py "path\to\game_directory" -r

Custom Output Directory

py unity_image_extractor.py "source" -o "custom_output_dir" -r

📁 Output Structure

Images are saved to Unity_Image_Extractor/extracted_images/, organized by source file structure:

extracted_images/
├── characters/
│   ├── hero_texture_001.png
│   ├── hero_texture_002.png
│   └── enemy_sprite_001.png
├── ui/
│   ├── button_normal.png
│   └── icon_health.png
└── environment/
    └── background_001.png

🛠️ Getting Started

Prerequisites

Installation

pip install UnityPy Pillow

⚠️ Educational Use Only

Important Disclaimer: This tool is intended for educational and personal research purposes only. All extracted assets are the intellectual property of their respective creators and copyright holders.

Do NOT:
• Use extracted assets for commercial purposes
• Redistribute assets without permission
• Violate copyright or EULA agreements

Recommended Use: Personal learning, asset analysis, modding with developer permission, educational research.

View on GitHub →