|
| 1 | +# analyze Command |
| 2 | + |
| 3 | +The `analyze` command extracts information from Unity Archives (e.g. AssetBundles) and SerializedFiles and dumps the results into a SQLite database. |
| 4 | + |
| 5 | +## Quick Reference |
| 6 | + |
| 7 | +``` |
| 8 | +UnityDataTool analyze <path> [options] |
| 9 | +``` |
| 10 | + |
| 11 | +| Option | Description | Default | |
| 12 | +|--------|-------------|---------| |
| 13 | +| `<path>` | Path to folder containing files to analyze | *(required)* | |
| 14 | +| `-o, --output-file <file>` | Output database filename | `database.db` | |
| 15 | +| `-p, --search-pattern <pattern>` | File search pattern (`*` and `?` supported) | `*` | |
| 16 | +| `-s, --skip-references` | Skip CRC and reference extraction (faster, smaller DB) | `false` | |
| 17 | +| `-v, --verbose` | Show more information during analysis | `false` | |
| 18 | +| `--no-recurse` | Do not recurse into sub-directories | `false` | |
| 19 | + |
| 20 | +## Examples |
| 21 | + |
| 22 | +Analyze all files in a directory: |
| 23 | +```bash |
| 24 | +UnityDataTool analyze /path/to/asset/bundles |
| 25 | +``` |
| 26 | + |
| 27 | +Analyze only `.bundle` files and specify a custom database name: |
| 28 | +```bash |
| 29 | +UnityDataTool analyze /path/to/asset/bundles -o my_database.db -p "*.bundle" |
| 30 | +``` |
| 31 | + |
| 32 | +Fast analysis (skip reference tracking): |
| 33 | +```bash |
| 34 | +UnityDataTool analyze /path/to/bundles -s |
| 35 | +``` |
| 36 | + |
| 37 | +See also [Analyze Examples](../../Documentation/analyze-examples.md). |
| 38 | + |
| 39 | +--- |
| 40 | + |
| 41 | +## What Can Be Analyzed |
| 42 | + |
| 43 | +The analyze command works with the following types of directories: |
| 44 | + |
| 45 | +| Input Type | Description | |
| 46 | +|------------|-------------| |
| 47 | +| **AssetBundle build output** | The output path of an AssetBundle build | |
| 48 | +| **Addressables folder** | `StreamingAssets/aa` folder from a Player build, including BuildLayout files | |
| 49 | +| **Entities content ** | `StreamingAssets/ContentArchives` folder for [Entities ](https://docs.unity3d.com/Packages/[email protected]/manual/content-management-intro.html) projects | |
| 50 | +| **Player Data folder** | The `Data` folder of a Unity Player build | |
| 51 | +| **Compressed Player builds** | The `data.unity3d` file will be analyzed like AssetBundles | |
| 52 | +| **BuildReport files** | The build report is typically found at a path like `Library/LastBuild.buildreport`and is a binary serialized file | |
| 53 | +| **AssetDatabase Artifacts** | The tool will work to some extent with serialized files created in the AssetDatabase artifact storage, inside the Library folder | |
| 54 | + |
| 55 | +> **Note**: Some platforms require extracting content from platform-specific containers first (e.g., `.apk` files on Android). |
| 56 | +
|
| 57 | +--- |
| 58 | + |
| 59 | +## Output Database |
| 60 | + |
| 61 | +The analysis creates a SQLite database that can be explored using tools like [DB Browser for SQLite](https://sqlitebrowser.org/) or the command line `sqlite3` tool. |
| 62 | + |
| 63 | +**Refer to the [Analyzer documentation](../../Analyzer/README.md) for the database schema reference and information about extending this command.** |
| 64 | + |
| 65 | +--- |
| 66 | + |
| 67 | +## Troubleshooting |
| 68 | + |
| 69 | +### File Loading Warnings |
| 70 | + |
| 71 | +``` |
| 72 | +Failed to load 'C:\....\MyData.db'. File may be corrupted or was serialized with a newer version of Unity. |
| 73 | +``` |
| 74 | + |
| 75 | +These warnings occur when the tool encounters non-Unity files in the analyzed directory. They are usually harmless—the analyze process continues and produces a valid database. |
| 76 | + |
| 77 | +**Solutions:** |
| 78 | +- Use `-p "*.bundle"` to filter by file extension |
| 79 | +- Use `--no-recurse` to limit directory depth |
| 80 | +- Use `-v` (verbose) to see which files are ignored |
| 81 | + |
| 82 | +The tool automatically ignores common non-Unity file types (`.txt`, `.json`, `.manifest`, etc.). |
| 83 | + |
| 84 | +### TypeTree Errors |
| 85 | + |
| 86 | +``` |
| 87 | +Error processing file: C:\...\TestProject_Data\level0 |
| 88 | +System.ArgumentException: Invalid object id. |
| 89 | +``` |
| 90 | + |
| 91 | +This error occurs when SerializedFiles are built without TypeTrees. The command will skip these files and continue. |
| 92 | + |
| 93 | +**Solution:** Enable **ForceAlwaysWriteTypeTrees** in your Unity build settings. See [Unity Content Format](../../Documentation/unity-content-format.md) for details. |
| 94 | + |
| 95 | +### SQL Constraint Errors |
| 96 | + |
| 97 | +``` |
| 98 | +SQLite Error 19: 'UNIQUE constraint failed: objects.id' |
| 99 | +``` |
| 100 | +or |
| 101 | +``` |
| 102 | +SQLite Error 19: 'UNIQUE constraint failed: serialized_files.id'. |
| 103 | +``` |
| 104 | + |
| 105 | +These errors occur when the same serialized file name appears in multiple sources: |
| 106 | + |
| 107 | +| Cause | Solution | |
| 108 | +|-------|----------| |
| 109 | +| Multiple builds in same directory | Analyze each build separately | |
| 110 | +| Scenes with same filename (different paths) | Rename scenes to be unique | |
| 111 | +| AssetBundle variants | Analyze variants separately | |
| 112 | + |
| 113 | +See [Comparing Builds](../../Documentation/comparing-builds.md) for strategies to compare different versions of builds. |
| 114 | + |
| 115 | +### Slow Analyze times, large output database |
| 116 | + |
| 117 | +Consider using the `--skip-references` argument. |
| 118 | + |
| 119 | +A real life analyze of a big Addressables build shows how large a difference this can make: |
| 120 | + |
| 121 | +* 208 seconds and producted a 500MB database (not specifying --skip-reference) |
| 122 | +* 9 seconds and produced a 68 MB file (with --skip-reference) |
| 123 | + |
| 124 | +The references are not needed for core asset inventory and size information. |
| 125 | + |
| 126 | +Note: When specifying `--skip-reference` some functionality is lost: |
| 127 | + |
| 128 | +* the `find-refs` command will not work |
| 129 | +* `view_material_shader_refs` and `view_material_texture_refs` will be empty |
| 130 | +* Queries that look at the relationship between objects will not work. For example the refs table is required to link between a `MonoBehaviour` and its `MonoScript`. |
| 131 | +* The `objects.crc32` column will be NULL/0 for all objects. This means: |
| 132 | + * No detection of identical objects by content hash (See [Comparing Builds](../../Documentation/comparing-builds.md)) |
| 133 | + * The `view_potential_duplicates` view relies partially on CRC32 to distinguish true duplicates |
| 134 | + |
| 135 | +Future work: The refs table contains a lot of repeated strings and could be made smaller and more efficient. It might also be prudent to control the CRC32 calculation using an independent flag. |
| 136 | + |
0 commit comments