Skip to main content

A Unity extraction and patching package

Project description


Discord server invite PyPI supported Python versions Win/Mac/Linux MIT Test and Publish

A Unity asset extractor for Python based on AssetStudio.

Next to extraction, it also supports editing Unity assets. So far following obj types can be edited:

  • Texture2D
  • Sprite(indirectly via linked Texture2D)
  • TextAsset
  • MonoBehaviour (and all other types that you have the typetree of)

If you need advice or if you want to talk about (game) data-mining, feel free to join the UnityPy Discord.

If you're using UnityPy a commercial project, a donation to a charitable cause or a sponsorship of this project is expected.

As UnityPy is still in active development breaking changes can happen. Those changes are usually limited to minor versions (x.y) and not to patch versions (x.y.z). So in case that you don't want to actively maintain your project, make sure to make a note of the used UnityPy version in your README or add a check in your code. e.g.

if UnityPy.__version__ != '1.9.6':
    raise ImportError("Invalid UnityPy version detected. Please use version 1.9.6")
  1. Installation
  2. Example
  3. Important Classes
  4. Important Object Types
  5. Credits


Python 3.6.0 or higher is required

via pypi

pip install UnityPy

from source

git clone
cd UnityPy
python -m pip install .



Visual C++ Redistributable is required for the brotli dependency.

Crash without warning/error

The C-implementation of the typetree reader can directly crash python. In case this happens, the usage of the C-typetree reader can be disabled by adding these two lines to your main file.

from UnityPy.helpers import TypeTreeHelper
TypeTreeHelper.read_typetree_c = False


The following is a simple example.

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 in ["Texture2D", "Sprite"]:
                    # parse the object data
                    data =

                    # create destination path
                    dest = os.path.join(destination_folder,

                    # 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

            # alternative way which keeps the original path
            for path,obj in env.container.items():
                if in ["Texture2D", "Sprite"]:
                    data =
                    # 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"

You probably have to read Important Classes and Important Object Types to understand how it works.

People with slightly advanced python skills should look at UnityPy/tools/ for a more advanced example. It can also be used as a general template or as an importable tool.

Setting the decryption key for Unity CN's AssetBundle encryption

The chinese version of Unity has its own inbuild option to encrypt AssetBundles/BundleFiles. As it's a feature of Unity itself, and not a game specific protection, it is included in UnityPy as well. To enable encryption simply use UnityPy.set_assetbundle_decrypt_key(key), with key being the value that the game that loads the budles passes to AssetBundle.SetAssetBundleDecryptKey.

Important Classes


Environment loads and parses the given files. It can be initialized via:

  • a file path - apk files can be loaded as well
  • a folder path - loads all files in that folder (bad idea for folders with a lot of files)
  • a stream - e.g., io.BytesIO, file stream,...
  • a bytes object - will be loaded into a stream

UnityPy can detect if the file is a WebFile, BundleFile, Asset, or APK.

The unpacked assets will be loaded into .files, a dict consisting of asset-name : asset.

All objects of the loaded assets can be easily accessed via .objects, which itself is a simple recursive iterator.

import io
import UnityPy

# all of the following would work
src = "file_path"
src = b"bytes"
src = io.BytesIO(b"Streamable")

env = UnityPy.load(src)

for obj in env.objects:

# saving an edited file
    # apply modifications to the objects
    # don't forget to use
with open(dst, "wb") as f:


Assets are a container that contains multiple objects. One of these objects can be an AssetBundle, which contains a file path for some of the objects in the same asset.

All objects can be found in the .objects dict - {ID : object}.

The objects with a file path can be found in the .container dict - {path : object}.


Objects contain the actual files, e.g., textures, text files, meshes, settings, ...

To acquire the actual data of an object it has to be read first. This happens via the .read() function. This isn't done automatically to save time because only a small part of the objects are of interest. Serialized objects can be set with raw data using .set_raw_data(data) or modified with .save() function, if supported.

Important Object Types

All object types can be found in UnityPy/classes.


  • .name
  • .image converts the texture into a PIL.Image
  • .m_Width - texture width (int)
  • .m_Height - texture height (int)


from PIL import Image
for obj in env.objects:
    if == "Texture2D":
        # export texture
        data =
        # edit texture
        fp = os.path.join(replace_dir,
        pil_img =
        data.image = pil_img


Sprites are part of a texture and can have a separate alpha-image as well. Unlike most other extractors (including AssetStudio), UnityPy merges those two images by itself.

  • .name
  • .image - converts the merged texture part into a PIL.Image
  • .m_Width - sprite width (int)
  • .m_Height - sprite height (int)


for obj in env.objects:
    if == "Sprite":
        data =


TextAssets are usually normal text files.

  • .name
  • .script - binary data (bytes)
  • .text - script decoded via UTF8 (str)

Some games save binary data as TextFile, so it's usually better to use .script.


for obj in env.objects:
    if == "TextAsset":
        # export asset
        data =
        with open(path, "wb") as f:
        # edit asset
        fp = os.path.join(replace_dir,
        with open(fp, "rb") as f:
            data.script =


MonoBehaviour assets are usually used to save the class instances with their values. If a type tree exists, it can be used to read the whole data, but if it doesn't exist, then it is usually necessary to investigate the class that loads the specific MonoBehaviour to extract the data. (example)

  • .name
  • .script
  • .raw_data - data after the basic initialisation


import json

for obj in env.objects:
    if == "MonoBehaviour":
        # export
        if obj.serialized_type.nodes:
            # save decoded data
            tree = obj.read_typetree()
            fp = os.path.join(extract_dir, f"{tree['m_Name']}.json")
            with open(fp, "wt", encoding = "utf8") as f:
                json.dump(tree, f, ensure_ascii = False, indent = 4)
            # save raw relevant data (without Unity MonoBehaviour header)
            data =
            fp = os.path.join(extract_dir, f"{}.bin")
            with open(fp, "wb") as f:

        # edit
        if obj.serialized_type.nodes:
            tree = obj.read_typetree()
            # apply modifications to the data within the tree
            data =
            with open(os.path.join(replace_dir, as f:


  • .samples - {sample-name : sample-data}

The samples are converted into the .wav format. The sample data is a .wav file in bytes.

clip : AudioClip
for name, data in clip.samples.items():
    with open(name, "wb") as f:


if == "Font":
    font : Font =
    if font.m_FontData:
        extension = ".ttf"
        if font.m_FontData[0:4] == b"OTTO":
            extension = ".otf"

    with open(os.path.join(path,, "wb") as f:


  • .export() - mesh exported as .obj (str)

The mesh will be converted to the Wavefront .obj file format.

mesh : Mesh
with open(f"{}.obj", "wt", newline = "") as f:
    # newline = "" is important

Renderer, MeshRenderer, SkinnedMeshRenderer


  • .export(export_dir) - exports the associated mesh, materials, and textures into the given directory

The mesh and materials will be in the Wavefront formats.

mesh_renderer : Renderer
export_dir: str

if mesh_renderer.m_GameObject:
    # get the name of the model
    game_object =
    export_dir = os.path.join(export_dir,


First of all, thanks a lot to all contributors of UnityPy and all of its users.

Also, many thanks to:

Project details

Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

UnityPy-1.9.26.tar.gz (1.6 MB view hashes)

Uploaded source

Built Distributions

UnityPy-1.9.26-cp311-cp311-win_amd64.whl (1.9 MB view hashes)

Uploaded cp311

UnityPy-1.9.26-cp311-cp311-win32.whl (1.1 MB view hashes)

Uploaded cp311

UnityPy-1.9.26-cp310-cp310-win_amd64.whl (1.9 MB view hashes)

Uploaded cp310

UnityPy-1.9.26-cp310-cp310-win32.whl (1.1 MB view hashes)

Uploaded cp310

UnityPy-1.9.26-cp39-cp39-win_amd64.whl (1.9 MB view hashes)

Uploaded cp39

UnityPy-1.9.26-cp39-cp39-win32.whl (1.1 MB view hashes)

Uploaded cp39

UnityPy-1.9.26-cp38-cp38-win_amd64.whl (1.9 MB view hashes)

Uploaded cp38

UnityPy-1.9.26-cp38-cp38-win32.whl (1.1 MB view hashes)

Uploaded cp38

UnityPy-1.9.26-cp37-cp37m-win_amd64.whl (1.9 MB view hashes)

Uploaded cp37

UnityPy-1.9.26-cp37-cp37m-win32.whl (1.1 MB view hashes)

Uploaded cp37

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page