Unity refreshes the Asset Database in the following situations:
AssetDatabase.Refresh
from code. Some other AssetDatabase
APIs trigger a refresh, but only for the assets you specify.Unity performs the following steps during an Asset Database refresh:
Assets
and Packages
folders have been added, modified, or deleted since the last check and update the Asset Database accordingly.Unity restarts the Asset Database refresh process if:
OnPostProcessAllAssets
, you call any of the following:
ForceReserializeAssets
AssetImporter.SaveAndImport
AssetDatabase
API that queues an additional refresh, such as MoveAsset, CreateAsset and ImportAsset.The Asset Database keeps track of two types of Asset dependencies: static dependencies and dynamic dependencies. If any dependency of an asset changes, then Unity reimports the asset.
A static dependency is a value, setting, or property that an importer depends on. Static dependencies are known before the asset is imported, and are not affected by the behavior of the importer during the import process. If any of an asset’s static dependencies change, then Unity re-imports the asset.
Static dependencies include:
Dynamic dependencies are defined by the content of the source asset and are usually discovered during the import process. For example, a shaderA program that runs on the GPU. More info
See in Glossary might reference another shader, and a 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 might depend on other prefabs.
The importer might also use a global state conditionally based on the content of the source asset, in which case it also becomes a dynamic dependency. Examples of this are the target platform, the project’s color space, the graphics API, the scripting runtime version, or the Texture compressionA method of storing data that reduces the amount of storage space it requires. See Texture Compression, Animation Compression, Audio Compression, Build Compression.
See in Glossary state.
Unity stores dynamic dependencies of an asset in an AssetImportContext
.
In the list of changed or added files, Unity gathers the ones that relate to code, and sends them to the script compilation pipeline. The compiler generates assemblies from the script files and assembly definition files in your project. For more information on this step, refer to Organizing scripts into assemblies.
Each asset’s importer processes that type of asset, and identifies files to import based on the file extensions. For example, the TextureImporter is responsible for importing .jpg, .png and .psd files, among others.
There are two types of importers:
Unity processes all native importers first, and then all scripted importers in a separate phase.
The AssetPostprocessor
class provides a range of callbacks which allow you to perform work before (preprocessing) and after (postprocessing) import for different asset types. For the details of these callbacks and usage examples, refer to the AssetPostprocessor
API reference.
Hot reloading is the process of applying changes to scripts and assets while the Editor is open. This might happen while the Editor is in Play mode or Edit mode and requires no restart of the Editor for changes to take effect.
When you change and save a script, Unity hot-reloads all of the project’s script data. It first stores the values of serializable variables in all loaded scripts, reloads the scripts, then restores the values. Data stored in non-serializable variables is lost.
This affects all Editor windows and all MonoBehaviour scripts in the project. Unlike other cases of serialization, Unity serializes private fields by default when reloading, even if they don’t have the SerializeField attribute.
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.