# How Asset Data works

## The **`AssetData`** system is divided in a few classes:

### <mark style="color:purple;">**`Assets`**</mark>&#x20;

* This <mark style="color:blue;">`class`</mark> caches all the <mark style="color:purple;">**`AssetDatabases`**</mark> in the game, its where we retrieve the asset we want. We can use the getters to specify which asset from a database to retrieve it.

### <mark style="color:purple;">**`DatabaseAsset`**</mark>

* A <mark style="color:blue;">`class`</mark> that contains a reference for the **`Name`** and **`DatabaseName`** of an asset, this is used to load them in a convenient way as the class is used when we generate the database code.

### <mark style="color:purple;">**`AssetDatabase`**</mark>

* <mark style="color:purple;">**`ScriptableObject`**</mark> that loads all assets present on an <mark style="color:purple;">**`AddressablesGroup`**</mark>, adding them to a list of assets and generating a <mark style="color:blue;">`static class`</mark> with <mark style="color:purple;">**`DatabaseAssets`**</mark> related to those assets.

### <mark style="color:purple;">`WorldObjectAssetReference`</mark>

* A <mark style="color:blue;">`class`</mark> used for world object assets, assets that can be placed in the world as a <mark style="color:purple;">**`GameObject`**</mark>, this has the purpose of creating a way to reference database assets via the inspector, without having to look for a prefab, it is also generated by the asset data system.

### <mark style="color:purple;">**`AssetDatabaseSettings`**</mark>

* a <mark style="color:purple;">**`ScriptableSettings`**</mark> <mark style="color:blue;">class</mark> that loads all the <mark style="color:purple;">**`AssetDatabases`**</mark>. Everything here is automated, you don't have to mess with. Its useful to see if all the databases are loaded, or to ignore code generation.

{% hint style="info" %}

## The system will automatically load all databases and generate the code/assets for it when a project reload is triggered or when the UI for the settings is opened.

{% endhint %}

## How it works

Whenever the code/asset generation is triggered, the system will scan for asset databases that are not loaded, load them in the list and then start the generation process.

The generation process simply iterates through each database and generate a static class of an <mark style="color:purple;">**`DatabaseAsset`**</mark> for each item in the database.

<figure><img src="https://3495811604-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F95OhrYYgKj0eUTnfM9sL%2Fuploads%2FV9m30tL9iWEJYT8KP4DD%2Fimage.png?alt=media&#x26;token=be2425c2-a28e-4044-a611-4d30d9e9dd37" alt=""><figcaption><p>This is an example of a generated class.</p></figcaption></figure>

The system will also generate a bunch of <mark style="color:purple;">**`WorldObjectAssetReferences`**</mark>, this is done on all assets that can be cast to GameObjects, they can be used in the inspector to reference an database asset.
