Tutorial Unity Lossless compression of Unity games

Radorei

Newbie
Dec 15, 2022
69
271
1. Motivation

Most Unity developers seem to not have the sufficient technical knowledge to ship their games in a storage-optimized state. As such, after installation, they become bloated and occupy storage space that could be utilized for more useful stuff. The major culprit for this is the Unity Creator which stores texture data in the GPU-friendly DXGI format by default (better than RAW, but way worse than PNG). So without the developer taking steps to pack this data in one of the ways which I will show in this guide, the game data remains bloated. The worst offenders are pixel-art and Live2D games. Our goal is to do what the developers didn't and pack the game as small as it can be, without compromising asset quality.

2. Requirements:
  • The game uses Unity version 5 (released in 2015) or newer
  • You gave installed
  • Reverse-engineered empty Unity archive in the data.zip attachment
3. Which games can be compressed

3.1. Zip compression ratio

The easiest way to tell is by looking at the compression ratio (uncompressed size/compressed size) while the game is still in the downloaded archive (.zip, .7z, .rar, etc.). I will use Robolife 2 as an applied example. 7Zip info shows a compression rate of 3143MB / 1684MB = 1.86. Pixeldrain is nice enough to show us the ratio before we even download the game.
You don't have permission to view the spoiler content. Log in or register now.
Use these ratios as a rule of thumb:
  • <1.2: The game may not be compressible at all. But even if it is, it's not worth the effort.
  • 1.2-1.6: May or may not be compressible. We will check in the next section.
  • >1.6: Most likely can be compressed.

3.2 Game file structure

Look inside Game/Game_Data folder. Depending on what you see, the game can or cannot be compressed.
You don't have permission to view the spoiler content. Log in or register now.
  • StreamingAssets folder. This folder most likely already compressed (you can try the alternative method, but it rarely helps). This file management system is the one recommended by Unity, which gives developers more control over game files. This is more involved as not using this system (hence why not all games have this folder), but if it is used, the developers usually know what they are doing.
  • data.unity3d or other *.unity3d files. These archive files are most likely already compressed. You can double-check by opening them with UABEA. If you get a prompt saying the bundle is compressed, then it really is. The goal of this guide is to create such an archive ourselves.
    You don't have permission to view the spoiler content. Log in or register now.
  • *.resource files. These can be compressed. They are accompanied by *.assets and maybe *.assets.resS files with the same name.
4. Step-by-step Guide
  1. (Optional) Back up the game.
  2. Go to Game_Data folder.
  3. Make a new temporary folder.
  4. Move all the resources.*, level*, sharedassets* files to the temporary folder.
    You don't have permission to view the spoiler content. Log in or register now.
    The Resources folder and globalgamemanagers* are small and compress poorly, but I also like to include them to keep the Game_Data folder clean.
  5. DO NOT move the app.info, boot.config, *.json or *.unity3d files. They need to stay outside.
  6. Extract the empty Unity archive (data.unity3d) from the attachment into the Game_Data folder. If there already exists a data.unity3d file inside the Game_Data folder, DO NOT OVERWRITE IT. Back it up instead.
  7. Open the data.unity3d archive with UABEA. In case the game came with this file and it is compressed, uncompress it to memory.
    You don't have permission to view the spoiler content. Log in or register now.
  8. Click 'Import All' and select the temporary folder.
  9. Save the archive (File > Save or Ctrl+S).
    You don't have permission to view the spoiler content. Log in or register now.
  10. Open the saved uncompressed archive (This step may seem redundant, but it's how UABEA works).
  11. Compress the archive (File > Compress). You have to save it with a different name. The compression algorithm doesn't seem to make much difference to me. I use LZ4.
    You don't have permission to view the spoiler content. Log in or register now.
  12. Wait :). Or do something else, it may take a while.
    You don't have permission to view the spoiler content. Log in or register now.
  13. Close UABEA.
  14. Delete (to Recycle Bin as a backup) the temporary folder and the uncompressed archive.
  15. Rename the compressed archive to data.unity3d.
    You don't have permission to view the spoiler content. Log in or register now.
  16. (Optional) Test the game to see it still works.
Pros and Cons:
+ The compressed files can be shared with others. Very useful for uploading.
+ The result is hardly distinguishable from games that were compressed by the developers.
- It takes quite some time. Both in manual steps, and during compression.
- You have to re-compress the game for every new version you want to play.
- Depending on your computer skills, it may not be easy to do.

5. Alternative method

This method is not specific to Unity, but I think it's worth including here. Use this if the compressed archive method failed, or the results were unsatisfying. If the previous method already worked, this one as well will not do much.
  1. Open Right Click > Properties of the Game_Data folder.
    You don't have permission to view the spoiler content. Log in or register now.
  2. Click Advanced then Compress contents to save space
    You don't have permission to view the spoiler content. Log in or register now.
  3. Click Okon both windows, then confirm the changes for all files and folders.
    You don't have permission to view the spoiler content. Log in or register now.
  4. Wait for it to finish, and check the results.
    You don't have permission to view the spoiler content. Log in or register now.
Pros and Cons:
+ Easy and fast to do (except maybe waiting for it to compress)
- The game needs to be in a NTFS Windows partition (Linux and MacOS have alternatives to this such as Btrfs and ZFS)
- The results are compressed only on your computer. You cannot share them while still being compressed
- The results seem to be worse on average compared to the previous method.