Use the AssetDatabase class to customize your asset pipeline and create tools to access, load, create and manipulate assets with your own scriptsA piece of code that allows you to create your own Components, trigger game events, modify Component properties over time and respond to user input in any way you like. More info
See in Glossary, to extend the way the Editor works. It is an Editor class, so its features are not available at runtime in standalone builds.
The AssetDatabase class has a large number of methods that allow you to access and perform operations on assets in exactly the same way that the Unity Editor itself does. You can create, import, delete, copy, move, load, and save assets, and search the asset database.
This means you can create anything from simple adjustments to powerful tools and customizations to your project’s asset workflow, using Unity’s Editor scripting and Editor window customization.
For a simple example, see the documentation for the AssetDatabase.ForceReserializeAssets method. It shows how you can add a menu item to the Editor that gives you more control over how certain asset bundles should be upgraded when you upgrade your project to a newer version of Unity.
For the full list of methods available, and documentation for each of the methods, see the AssetDatabase scripting API page.
From a scripting point of view, what Unity considers an “asset” is slightly different than what you see displayed in the Project windowA window that shows the contents of your Assets
folder (Project tab) More info
See in Glossary. The files that you place in your project’s Assets folder are the source files for your assets, but they differ conceptually to the asset objects that the Unity Editor works with. When Unity imports asset files, it processes them and generates an imported result: serialized C# objects that derive from UnityEngine.Object. From a scripting point-of-view, the assets that you have access to when scripting in the Unity Editor are these imported results.
For example, an asset that might start off as a binary file, such as a JPEG or PNG image file, is converted to a C# object whose type is a specialization of UnityEngine.Object. In the case of JPEG or PNG files, they are converted to serialized instances of the TextureAn image used when rendering a GameObject, Sprite, or UI element. Textures are often applied to the surface of a mesh to give it visual detail. More info
See in Glossary class, which in turn inherits from UnityEngine.Object. The serialized object data is then stored as an artifact in the Library folder. So, when you access a Texture asset with a script, you are not accessing the original JPEG or PNG file, you are accessing the serialized version of the C# Texture object that was generated when the original image file was imported. The .meta file which Unity creates during the import process, stored next to the original asset file, contains the asset’s import settings, and contains a GUID which allows Unity to connect the original asset file with the artifact in the asset database.
Some types of asset files that Unity itself creates, such as .prefabAn asset type that allows you to store a GameObject complete with components and properties. The prefab acts as a template from which you can create new object instances in the scene. More info
See in Glossary, .sceneA Scene contains the environments and menus of your game. Think of each unique Scene file as a unique level. In each Scene, you place your environments, obstacles, and decorations, essentially designing and building your game in pieces. More info
See in Glossary, .asset, and .mat, already contain serialized data in their source file, so the artifact file that Unity produces and caches is very similar to the source file. The source files for these, for example a .mat material file in your project’s Assets folder, are human-readable (provided Asset Serialization Mode is set to Force Text, which is the default setting). This is in contrast to binary asset files imported from external sources such as textures or audio, where the files are not normally human-readable.
Asset files can contain multiple serialized objects, and each of these can be considered an “asset” for the purposes of scripting with the AssetDatabase methods. For example, a .prefab asset file could contain a serialized GameObjectThe fundamental object in Unity scenes, which can represent characters, props, scenery, cameras, waypoints, and more. A GameObject’s functionality is defined by the Components attached to it. More info
See in Glossary with multiple components attached. Each of those components are also serialized as objects in the asset file, and so when accessing the contents of the prefab asset using AssetDatabase methods, the component objects within the asset file are considered sub assets, (explained in more detail below).
The serialized objects generated during the import process are called artifacts, and Unity stores them in the Asset Database’s cache of import artifacts, in the Library folder of your project. They are treated as cached data because Unity can always regenerate them from the source assets, using the importer settings and project settingsA broad collection of settings which allow you to configure how Physics, Audio, Networking, Graphics, Input and many other areas of your project behave. More info
See in Glossary saved in your project.
You can inspect the artifacts produced for the assets in your project by using the Import Activity window, which reveals the specific cached artifact files that Unity generates, along with other useful information such as when the import happened, and how long it took.
Each artifact file name is a unique hash (a GUID) with no file extension. Unity separates these files into subfolders, each subfolder with a name matching the first two characters of the artifact filename.
These artifact files contain binary data, and are not designed to be human-readable. While it’s useful to understand that these files contain the data used by the asset database, you do not need to view, edit, or use these files directly while working with Unity. Instead, the AssetDatabase class provides the methods necessary to work with assets within the Editor.
Because Unity can store multiple serialized objects within the same asset file, Unity has a concept of the main asset within any asset file. When Unity creates asset files that contain a single asset, such as a material, the main asset is always that single asset. For other types containing more than one serialized asset object, the main asset is always the first asset added to the file, unless otherwise specified with the SetMainObject method.
You can sometimes see sub-assets in the Project window of the Editor, if those sub-assets are of certain types. For example, looking at this FBX asset file containing a “Space Frigate” model in the Project window, its view has been expanded to reveal that it has a material and a meshThe main graphics primitive of Unity. Meshes make up a large part of your 3D worlds. Unity supports triangulated or Quadrangulated polygon meshes. Nurbs, Nurms, Subdiv surfaces must be converted to polygons. More info
See in Glossary as sub-assets.
Assets can also have sub-asset types that do not show in the Project window like this. For example, the “Space Frigate” asset file above actually contains more than the two sub-assets displayed in the Project window. You can see the real number of assets when you access the asset file using AssetDatabase methods, as demonstrated in the script below:
using UnityEngine; using UnityEditor; public class Example : MonoBehaviour { [MenuItem("AssetDatabase/InspectAssets")] private static void InspectAssets() { Object[] data = AssetDatabase.LoadAllAssetsAtPath("Assets/Space Frigate.fbx"); Debug.Log(data.Length + " Assets"); foreach (Object o in data) { Debug.Log(o); } } }
In this case, the output would show that the imported, serialized version of this file contains six assets:
6 Assets Space Frigate (UnityEngine.GameObject) space_frigate_0 (UnityEngine.Material) space_frigate_0 (UnityEngine.Mesh) Space Frigate (UnityEngine.Transform) Space Frigate (UnityEngine.MeshRenderer) Space Frigate (UnityEngine.MeshFilter)
This is because the GameObject, material, the mesh data itself, and each of the components that Unity automatically added to the GameObject during the import process (the Transform, the MeshFilter, and the MeshRenderer), each count as a separate serialized object. Therefore they are sub-assets of the asset file, and as far as the Asset Database API is concerned, are each a separate asset.
If you are scripting using the AssetDatabase class, it’s important to understand how the order of Unity’s import processes can affect your scripts, otherwise you may get unexpected results. The order is as follows:
Scripts are always imported and compiled before all other regular assets, because the Editor needs to know whether there are custom asset post-processors or scripted importers in the project. This ensures that the Editor uses any new or changed importers or post-processors when importing the rest of the non-script assets.
The InitializeOnLoad callback is often used to run some code on project startup or when scripts change. As shown in the list above, this callback is run after Unity reloads the domain, but before it starts importing assets. This means if you’re using the [InitializeOnLoad] callback to access assets, your code is executed before the current asset import cycle completes. In particular:
For assets being imported for the first time, methods like AssetDatabase.LoadAssetAtPath, AssetDatabase.FindAssets, ShaderA program that runs on the GPU. More info
See in Glossary.Find, Resources.Load will return null, since those assets have not yet been imported.
For assets that have already been imported at least once, methods like AssetDatabase.LoadAssetAtPath, AssetDatabase.FindAssets, Shader.Find, Resources.Load will return the previous (outdated) version of the asset if it was modified before reloading the domain, since domain reload occurs before the regular asset import phase.
When you are writing scripted importers, asset pre-processors, and asset post-processors, you should not make your code assume that other specific assets are already imported according to any particular order. When importing, Unity groups assets into queues by type, and while the types are imported in a predefined order, assets within a queue of the same type are imported in an arbitrary order unless you use ScriptedImporter.GatherDependenciesFromSourceFile. Using GatherDependenciesFromSourceFile
also creates a dependency between the assets, so if one asset is modified, the other that depends on it is reimported.
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.
When you visit any website, it may store or retrieve information on your browser, mostly in the form of cookies. This information might be about you, your preferences or your device and is mostly used to make the site work as you expect it to. The information does not usually directly identify you, but it can give you a more personalized web experience. Because we respect your right to privacy, you can choose not to allow some types of cookies. Click on the different category headings to find out more and change our default settings. However, blocking some types of cookies may impact your experience of the site and the services we are able to offer.
More information
These cookies enable the website to provide enhanced functionality and personalisation. They may be set by us or by third party providers whose services we have added to our pages. If you do not allow these cookies then some or all of these services may not function properly.
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us to know which pages are the most and least popular and see how visitors move around the site. All information these cookies collect is aggregated and therefore anonymous. If you do not allow these cookies we will not know when you have visited our site, and will not be able to monitor its performance.
These cookies may be set through our site by our advertising partners. They may be used by those companies to build a profile of your interests and show you relevant adverts on other sites. They do not store directly personal information, but are based on uniquely identifying your browser and internet device. If you do not allow these cookies, you will experience less targeted advertising. Some 3rd party video providers do not allow video views without targeting cookies. If you are experiencing difficulty viewing a video, you will need to set your cookie preferences for targeting to yes if you wish to view videos from these providers. Unity does not control this.
These cookies are necessary for the website to function and cannot be switched off in our systems. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms. You can set your browser to block or alert you about these cookies, but some parts of the site will not then work. These cookies do not store any personally identifiable information.