Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Extract files/assets from a .unitypackage file

Discussion in 'Formats & External Tools' started by GregoryFenn, Jun 8, 2019.

  1. GregoryFenn

    GregoryFenn

    Joined:
    Feb 13, 2018
    Posts:
    43
    ,Hi all,

    I have bought dozens of expensive Asset Store packs with things like audio files (usually in .wav format) and 3D models (.fbx or .blend). But I would like to open the downloaded local copy of my purchase and move/edit/hack the assets directly, not just to the extent possible in the Unity Editor after importing. Is this possible??

    The assets are saved (in Windows 10) at : "C:\Users\GFenn\AppData\Roaming\Unity\Asset Store-5.x".

    For example, one audio asset of retro sound effects is in the folder: "C:\Users\GFenn\AppData\Roaming\Unity\Asset Store-5.x\Zero Rare\AudioSound FX" and the file is called "Sound FX - Retro Pack.unitypackage"

    Some old articles said you can unzip it with 7Zip, by treating the file as a .tar folder, but this produced a garbage file for me that both Windows Media Player and Audacity were unable to read.

    Likewise, other .unitypackage files that I have bought and downloaded may contain 2D Sprites and Textures that I would like to expand and play with in tools like GIMP or Krita.

    Please can someone tell me how to directly access the assets I bought? I'm sure it's possible because if you double-click on an asset (e.g. Texture) in your Asset Folder in Unity, then it will open Krita (on my system, could be GIMP or Photoshop or MS Paint for others). So it's not like the assets are being encrypted or purposely hidden.

    I know one "solution" is just to import everything into a dummy Unity game, and then open the Assets folder on my system, but I want eventually to write a batch/cmd script to copy and paste ALL the png/wav/blend/fbx etc files to a new folder on my system, effectively segmenting it away from Unity altogether.
     
    chelnok likes this.
  2. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
  3. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    1,802
    I only inspected one file I happened to have on my desktop, so there are probably nuances.

    Code (CSharp):
    1. $  tar zxvf Package.assetpackage
    This produced a series of funky-named folders, one for each entry you would see in the Import dialogue. There could be thousands, so take care to unpack these in an empty work area. The names are hex digits, likely encryption hashes since they're too long to be guids. Maybe they're encryption hashes OF guids.

    In each hash folder, there is a very short file called "pathname". The contents of this is the full path to the asset file to be imported, e.g.,
    Assets/Shaders/Foobar.shader
    . Then there is a file called "asset.meta"; if you replace the word "asset" with the contents of the "pathname" you get the
    Assets/Shaders/Foobar.shader.meta
    you will need. If this was a folder, that's all you get, since Unity doesn't generally do anything else special for folders. For other assets, there will be an "asset" which you rename the same way, the actual contents of the file,
    Assets/Shaders/Foobar.shader
    , and also a "preview.png" which is a thumbnail you would see on the Asset Store website.

    Someone more motivated could make a very short .CMD, .sh, or .py file which unpacks assetpackages for you. I hope this doesn't run afoul of Unity rules, but honestly, this file format is made for convenience not security.
     
    chelnok and luvjungle like this.
  4. lwerdna

    lwerdna

    Joined:
    Dec 4, 2019
    Posts:
    1
    Run this from the folder with all the hash folder names. Output will be in /tmp.

    Code (csharp):
    1. #!/usr/bin/env python3
    2. import os
    3. import re
    4. import shutil
    5. for path in os.listdir('.'):
    6.     if not re.match(r'^[a-f0-9]{32}$', path):
    7.         continue
    8.     src = os.path.join(path, 'asset')
    9.     if not os.path.exists(src):
    10.         continue
    11.     print('source: ', src)
    12.     with open(os.path.join(path, 'pathname')) as fp:
    13.         dst = fp.read()
    14.     if dst.endswith('\x0a\x30\x30'):
    15.         dst = dst[0:-3]
    16.     dst = os.path.join('/tmp', dst)
    17.     print('destination: -%s-' % dst)
    18.     dst_dir = os.path.dirname(dst)
    19.     print('creating dir: ', dst_dir)
    20.     os.makedirs(dst_dir, exist_ok=True)
    21.     print('copying...')
    22.     shutil.copy(src, dst)
     
    chelnok, luvjungle and Morphet like this.
  5. LilGames

    LilGames

    Joined:
    Mar 30, 2015
    Posts:
    510
    --- 8< ---

    Forget about snooping around in the .unitypackage file and do this:
    - Create a new Unity project in a folder called "Unity Audio Packages"
    - Make sure it's on a drive with lots of space (don't waste precious SSD drive space for example)
    - Open the project and now download and import all your audio libraries.
    - Open File Explorer (or Mac equivalent) and go look in /Assets/ folder of your new project and there are all the files! Make copies and edit them as you like.

    Same applies to textures and any other file formats.
     
  6. Krishx007

    Krishx007

    Joined:
    Jul 15, 2014
    Posts:
    14
    Python 3 required to run this script. Download here
    https://www.python.org/downloads/release

    Tutorial to run script




     
  7. Morphet

    Morphet

    Joined:
    May 28, 2020
    Posts:
    1
    Thanks a lot for this script, it helped!
     
    Doo-Joo likes this.
  8. Wappenull

    Wappenull

    Joined:
    Oct 29, 2013
    Posts:
    48
    Bezoro and greene_tea92 like this.
  9. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    8,848
  10. greene_tea92

    greene_tea92

    Joined:
    Jun 26, 2017
    Posts:
    21
  11. SwitchHD

    SwitchHD

    Joined:
    Nov 11, 2017
    Posts:
    2
    pietwelve2, chelnok and Hobodi like this.