Skip to content

Commit 7f79d02

Browse files
authored
Docs: Addressables local→remote dependency example (#67)
Add SQLite example query and narrative for finding explicit addressables in locally classified bundles that depend on explicit addressables in remote bundles, using build layout JSON from analyze. Update addressables-build-reports schema notes and cross-link to the example.
1 parent 393e887 commit 7f79d02

2 files changed

Lines changed: 107 additions & 10 deletions

File tree

Documentation/addressables-build-reports.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ Contains groups used in the build and whether they're pack separate or together.
5151

5252
#### `addressables_build_group_schemas`
5353
Map groups to their schemas
54-
* schema_rid maps to addressables_group_schemas.id
54+
* schema_rid maps to addressables_build_schemas.id
5555
* group_id maps to addressables_build_groups.id
5656

5757
#### `addressables_build_schemas`
5858
Contain schema names.
59-
* id maps to addressables_group_schemas.id
59+
* id is referenced by `addressables_build_group_schemas.schema_rid` and `addressables_build_schema_data_pairs.schema_id`
6060

61-
#### `add_build_schema_data_pairs`
61+
#### `addressables_build_schema_data_pairs`
6262
Contains key value pairs of schema settings at time of build.
6363
* schema_id maps to addressables_build_schemas.id
6464

@@ -83,8 +83,8 @@ Explicit assets (marked as Addressable). Has Addressable name and asset informat
8383

8484
#### `addressables_build_explicit_asset_internal_referenced_other_assets`
8585
Map explicit assets to other assets they refer to. For instance a prefab to its underlying FBX
86-
* referencing_asset_rid maps to addressables_build_explicit_assets.id
87-
* data_from_other_asset_Id maps to addressables_build_data_from_other_assets.id
86+
* explicit_asset_id maps to addressables_build_explicit_assets.id
87+
* internal_referenced_other_asset_rid maps to addressables_build_data_from_other_assets.id
8888

8989
#### `addressables_build_data_from_other_assets`
9090
Assets added into the build implicitly by explicitly defined assets.
@@ -110,6 +110,10 @@ UnityDataTools.exe "C:\\Temp\\MyExtractedFiles" -o "addressables_analysis.db" -p
110110

111111
You can analyze a directory with both asset bundles (*.bundle) and json files (*.json) at the same time.
112112

113+
### Cross-group dependencies (local → remote)
114+
115+
To find explicit addressable assets whose bundle is classified as **local** (for example by `load_path`) but that depend on explicit addressables in **remote** bundles, see [Example: Local Addressable groups depending on remote groups](analyze-examples.md#example-local-addressable-groups-depending-on-remote-groups) in analyze-examples.md.
116+
113117
### Sample Queries
114118

115119
Once the data is in the database, you can run queries to analyze your Addressables build:
@@ -118,12 +122,12 @@ Once the data is in the database, you can run queries to analyze your Addressabl
118122
#### Find all implicit assets for an explicit asset
119123
```sql
120124
-- Find implicitly included assets for a given explicit asset id
121-
SELECT a.explicit_asset_id, b.id, b.asset_path, b.asset_path
122-
FROM addressables_build_explicit_asset_internal_referenced_other_assets a,
125+
SELECT a.explicit_asset_id, b.id, b.asset_path
126+
FROM addressables_build_explicit_asset_internal_referenced_other_assets a,
123127
addressables_build_data_from_other_assets b
124-
WHERE a.internal_referenced_other_asset_rid = b.id
125-
AND a.build_id = b.build_id;
126-
AND a.explicit_asset_id = 5092
128+
WHERE a.internal_referenced_other_asset_rid = b.id
129+
AND a.build_id = b.build_id
130+
AND a.explicit_asset_id = 5092
127131
AND a.build_id = 3;
128132
```
129133

Documentation/analyze-examples.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ Shader Graphs/CustomLightingBuildingsB 113.4 KB 1b2fdfe013c58ffd57d7663
6868

6969
See [buildreport.md](buildreport.md) for information about using analyze to look at BuildReport files.
7070

71+
72+
7173
## Example: Using AI tools to help write queries
7274

7375
This is not a tutorial on using AI tools. However one useful tip:
@@ -261,3 +263,94 @@ Examples of alternative sources of build information:
261263
* The Editor log reports a lot of information during a build.
262264
* Regular AssetBundle builds create [.manifest files](https://docs.unity3d.com/Manual/assetbundles-file-format.html), which contain information about the source assets and types.
263265
* Addressable builds do not produce BuildReport files, nor .manifest files. But UnityDataTools supports analyzing the [Addressables Build Reports](addressables-build-reports.md) and will populate the `addressables_build_explicit_assets` and `addressables_build_data_from_other_assets` tables.
266+
267+
## Example: Local Addressable groups depending on remote groups
268+
269+
A common scenario when working with remote content, is to add a new piece of content to a local Addressable group that depends upon content in a remote Addressable group. Often this is fine, but if it's unexpected it can lead to the game stalling while downloading a large quantity of remote content. This example prints out content in local Addressable groups that depend upon content in remote groups.
270+
271+
UnityDataTools does **not** store a boolean “local” or “remote” flag. Each bundle row has a **`load_path`** string (table `addressables_build_bundles`). You can classify bundles for a given project by testing that string—for example:
272+
273+
* **Remote bundle:** `load_path` starts with `https://` or `http://` (typical for remote profiles).
274+
* **Local bundle:** not matched by the above (often paths containing `{UnityEngine.AddressableAssets.Addressables.RuntimePath}` or similar). You may refine this for your naming or add conditions such as non-empty `load_path` if you need to exclude odd rows.
275+
276+
In this case, we want to know about both explicitly referenced assets and implicitly referenced assets. Explicitly referenced assets are assets that you have directly linked in another bundle, while implicitly referenced assets are dependencies of your source asset. For example, a prefab in a local group may explicitly reference a material in a remote group.
277+
278+
**1. Produce a database from your build reports** (adjust paths; on Windows use backslashes or quoted paths):
279+
280+
```
281+
UnityDataTool analyze "C:\YourProject\Library\com.unity.addressables\BuildReports" -o addressables_analysis.db
282+
```
283+
284+
**2. Find the `build_id`** for the report you care about (often the latest row):
285+
286+
```
287+
sqlite3 addressables_analysis.db "SELECT id, name, start_time FROM addressables_builds ORDER BY id DESC LIMIT 5;"
288+
```
289+
290+
Use that `id` as `:build_id` in the query below.
291+
292+
**3. List explicit assets in a local bundle that reference an explicit asset in a remote bundle**
293+
294+
The following uses a `UNION ALL` of the two explicit-explicit edge tables. Bundle `load_path` values are joined only so the `WHERE` clause can classify local vs remote bundles; they are not selected in the result. Column aliases **`local_*`** refer to the asset in the locally classified bundle (the referencing side), and **`remote_*`** to the depended-on asset in the remotely classified bundle. The **`dependency_type`** column uses short labels aligned with typical Addressables UI wording: **`explicit`** for edges from **ExternallyReferencedAssets**, and **`implicit`** for edges from **InternalReferencedExplicitAssets**. In both cases the dependency is still between **explicit addressables** in the build layout; non-addressable “other” assets are modeled separately in `addressables_build_explicit_asset_internal_referenced_other_assets` / `addressables_build_data_from_other_assets`.
295+
296+
```sql
297+
SELECT
298+
'explicit' AS dependency_type,
299+
src.addressable_name AS local_address,
300+
src.asset_path AS local_asset_path,
301+
sg.name AS local_group_name,
302+
tgt.addressable_name AS remote_address,
303+
tgt.asset_path AS remote_asset_path,
304+
tg.name AS remote_group_name
305+
FROM addressables_build_explicit_asset_externally_referenced_assets x
306+
JOIN addressables_build_explicit_assets src
307+
ON src.id = x.explicit_asset_id AND src.build_id = x.build_id
308+
JOIN addressables_build_explicit_assets tgt
309+
ON tgt.id = x.externally_referenced_asset_rid AND tgt.build_id = x.build_id
310+
JOIN addressables_build_bundles sb
311+
ON sb.id = src.bundle AND sb.build_id = src.build_id
312+
JOIN addressables_build_bundles tb
313+
ON tb.id = tgt.bundle AND tb.build_id = tgt.build_id
314+
JOIN addressables_build_groups sg
315+
ON sg.guid = src.group_guid AND sg.build_id = src.build_id
316+
JOIN addressables_build_groups tg
317+
ON tg.guid = tgt.group_guid AND tg.build_id = tgt.build_id
318+
WHERE x.build_id = :build_id
319+
AND NOT (COALESCE(sb.load_path, '') LIKE 'https://%' OR COALESCE(sb.load_path, '') LIKE 'http://%')
320+
AND (COALESCE(tb.load_path, '') LIKE 'https://%' OR COALESCE(tb.load_path, '') LIKE 'http://%')
321+
322+
UNION ALL
323+
324+
SELECT
325+
'implicit' AS dependency_type,
326+
src.addressable_name AS local_address,
327+
src.asset_path AS local_asset_path,
328+
sg.name AS local_group_name,
329+
tgt.addressable_name AS remote_address,
330+
tgt.asset_path AS remote_asset_path,
331+
tg.name AS remote_group_name
332+
FROM addressables_build_explicit_asset_internal_referenced_explicit_assets iref
333+
JOIN addressables_build_explicit_assets src
334+
ON src.id = iref.explicit_asset_id AND src.build_id = iref.build_id
335+
JOIN addressables_build_explicit_assets tgt
336+
ON tgt.id = iref.internal_referenced_explicit_asset_rid AND tgt.build_id = iref.build_id
337+
JOIN addressables_build_bundles sb
338+
ON sb.id = src.bundle AND sb.build_id = src.build_id
339+
JOIN addressables_build_bundles tb
340+
ON tb.id = tgt.bundle AND tb.build_id = tgt.build_id
341+
JOIN addressables_build_groups sg
342+
ON sg.guid = src.group_guid AND sg.build_id = src.build_id
343+
JOIN addressables_build_groups tg
344+
ON tg.guid = tgt.group_guid AND tg.build_id = tgt.build_id
345+
WHERE iref.build_id = :build_id
346+
AND NOT (COALESCE(sb.load_path, '') LIKE 'https://%' OR COALESCE(sb.load_path, '') LIKE 'http://%')
347+
AND (COALESCE(tb.load_path, '') LIKE 'https://%' OR COALESCE(tb.load_path, '') LIKE 'http://%');
348+
```
349+
350+
To print results from the command line, save the query to a file (e.g. `query.sql`) and run:
351+
352+
```
353+
sqlite3 addressables_analysis.db ".mode column" ".headers on" ".param set :build_id 1" ".read query.sql"
354+
```
355+
356+
Replace `1` with the `build_id` value found in step 2.

0 commit comments

Comments
 (0)