Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


AssetDatabase

An Interface for accessing assets and performing operations on assets.
Read time 8 minutesLast updated 4 days ago

Definition

  • Type: Class
  • Namespace: UnityEditor
  • Assembly: UnityEditor
public sealed class AssetDatabase

Static Fields

Value

Description

onImportPackageItemsCompletedCallback raised whenever a package import successfully completes that lists the items selected to be imported.

Static Properties

Property

Description

ActiveRefreshImportModeGets the refresh import mode currently in use by the asset database.
DesiredWorkerCountThe desired number of processes to use when importing assets, during an asset database refresh.
GlobalArtifactDependencyVersionChanges during Refresh if anything has changed that can invalidate any artifact.
GlobalArtifactProcessedVersionChanges whenever a new artifact is added to the artifact database.

Static Methods

Method

Description

AddObjectToAssetAdds objectToAdd to an existing asset at path.
AllowAutoRefreshDecrements an internal counter which Unity uses to determine whether to allow automatic AssetDatabase refreshing behavior.
AssetPathExistsCheck whether an asset exists at the given path in the database.
AssetPathToGUIDGet the GUID for the asset at
path
.
CanConnectToCacheServerChecks the availability of the Cache Server.
CanOpenAssetInEditorChecks if Unity can open an asset in the Editor.
CanOpenForEditQuery whether an Asset file can be opened for editing in version control and is not exclusively locked by another user or otherwise unavailable.
ClearImporterOverrideClears the importer override for the asset.
ClearLabelsRemoves all labels attached to an asset.
CloseCacheServerConnectionCloses an active cache server connection. If no connection is active, then it does nothing.
ContainsChecks whether a given object is an asset.
CopyAssetDuplicates the asset at path and stores it at newPath.
CopyAssetsDuplicates assets in paths and stores them in newPaths.
CreateAssetCreates a new asset in a native Unity format.
CreateFolderCreates a new folder, in the specified parent folder.
DeleteAssetDeletes the specified asset or folder.
DeleteAssetsLets you delete multiple assets or folders at once with performance benefits under version control.
DisallowAutoRefreshIncrements an internal counter which Unity uses to determine whether to allow automatic AssetDatabase refreshing behavior.
ExportPackageExports the assets identified by
assetPathNames
to a unitypackage file in
fileName
.
ExtractAssetCreates an external Asset from an object (such as a Material) by extracting it from within an imported asset (such as an FBX file).
FindAssetGUIDsSearches the asset database with a filter string and returns an array of GUIDs.
FindAssetsSearch the asset database using the search filter string.
ForceReserializeAssetsForcibly load and re-serialize the given assets, flushing any outstanding data changes to disk.
ForceToDesiredWorkerCountForces the Editor to use the desired amount of worker processes. Unity will either spawn new worker processes or shut down idle worker processes to reach the desired number.
GenerateUniqueAssetPathCreates a new unique path for an asset.
GetAllAssetBundleNamesObtain all the AssetBundle names registered in the Asset Database.
GetAssetBundleDependenciesGiven an assetBundleName, returns the list of AssetBundles that it depends on.
GetAssetDependencyHashReturns the hash of all the dependencies of an asset.
GetAssetOrScenePathReturns the path name relative to the project folder where the asset or scene is stored.
GetAssetPathReturns the path name relative to the project folder where the asset is stored.
GetAssetPathFromTextMetaFilePathGets the path to the asset file associated with a text .meta file.
GetAssetPathsFromAssetBundleReturns an array containing the paths of all assets marked with the specified AssetBundle name.
GetAssetPathsFromAssetBundleAndAssetNameGet the Asset paths for all Assets tagged with assetBundleName and named assetName.
GetAvailableImportersGets the importer types associated with a given Asset path.
GetCachedIconRetrieves the cached icon for the asset at the given path, without loading the asset. This is the icon shown in the Project window list view.
GetCacheServerAddressGets the IP address of the Cache Server in Editor Settings.
GetCacheServerEnableDownloadGets the Cache Server Download option from Editor Settings.
GetCacheServerEnableUploadGets the Cache Server Upload option from Editor Settings.
GetCacheServerNamespacePrefixGets the Cache Server Namespace prefix set in Editor Settings.
GetCacheServerPortGets the Port number of the Cache Server in Editor Settings.
GetCurrentCacheServerIpGets the IP address of the Cache Server currently in use by the Editor.
GetDefaultImporterReturns the Default Importer associated with the asset located at the supplied path. When no Importer override is set, then the default importer is used. Additional Resources: AssetDatabase.GetImporterOverride, AssetDatabase.ClearImporterOverride.
GetDependenciesReturns an array of all the assets that are dependencies of the asset at the specified pathName.
GetImplicitAssetBundleNameReturns the name of the AssetBundle that a given asset belongs to.
GetImplicitAssetBundleVariantNameReturns the name of the AssetBundle Variant that a given asset belongs to.
GetImporterOverrideReturns the type of the override importer.
GetImporterTypeReturns the type of the importer associated with an asset without loading the asset.
GetImporterTypesReturns the types of importers associated with the specified array of assets, without loading those assets.
GetLabelsObtains all labels of a given asset.
GetMainAssetTypeAtPathObtains the type of the main asset object.
GetMainAssetTypeFromGUIDObtains the type of the main object of a given asset.
GetScriptableObjectsWithMissingScriptCountChecks how many unloadable ScriptableObject instances are present in the specified asset.
GetSubFoldersObtains the subdirectories of a given directory in the Assets folder.
GetTextMetaFilePathFromAssetPathGets the path to the text .meta file associated with an asset.
GetTypeFromPathAndFileIDGets an object's type from an Asset path and a local file identifier.
GetUnusedAssetBundleNamesObtains any unused AssetBundle names in the Asset Database.
GUIDFromAssetPathGet the GUID for the asset at
path
.
GUIDToAssetPathGets the corresponding asset path for the supplied GUID, or an empty string if the GUID can't be found.
ImportAssetImport asset at path.
ImportPackageImports the package at
packagePath
into the current project.
InstanceIDsToGUIDsSets a NativeArray of GUIDs for every valid Instance ID that is an asset.
IsAssetImportWorkerProcessDetermines whether the current process is an Asset Import Worker process.
IsCacheServerEnabledChecks whether the Cache Server is enabled in Project Settings.
IsConnectedToCacheServerChecks connection status of the Cache Server.
IsDirectoryMonitoringEnabledReports whether Directory Monitoring is enabled.
IsForeignAssetDetermines whether a given asset is an external asset, also known as a foreign asset.
IsMainAssetChecks whether the asset is a main asset in the Project window.
IsMainAssetAtPathLoadedChecks whether the main asset object at
assetPath
is loaded in memory.
IsMetaFileOpenForEditQuery whether an asset's metadata (.meta) file is open for edit in version control.
IsNativeAssetDetermines whether the asset is a native asset.
IsOpenForEditQuery whether an Asset file is open for editing in version control.
IsSubAssetChecks whether the asset is part of another asset.
IsValidFolderGiven a path to a folder, returns true if it exists, false otherwise.
LoadAllAssetRepresentationsAtPathObtains all sub-assets at
assetPath
.
LoadAllAssetsAtPathObtains an array of all assets at
assetPath
.
LoadAssetAtPathRetrieves the first asset object of type
type
at given path
assetPath
.
LoadAssetByGUIDLoads an asset object of type
type
by given GUID
assetGUID
.
LoadMainAssetAtPathObtains the main asset object at
assetPath
.
LoadObjectAsyncLoads a specific Object and its dependencies from an Asset file asynchronously.
MakeEditableMakes a file open for editing in version control.
MoveAssetMove an asset file (or folder) from one folder to another.
MoveAssetsToTrashLets you move multiple assets or folders to trash at once with performance benefits under version control.
MoveAssetToTrashMoves the specified asset or folder to the OS trash.
OpenAssetOpens the asset with associated application.
RefreshImport any changed assets.
RefreshSettingsApply pending Editor Settings changes to the Asset pipeline.
RegisterCustomDependencyAllows you to register a custom dependency that Assets can be dependent on. If you register a custom dependency, and specify that an Asset is dependent on it, then the Asset will get re-imported if the custom dependency changes.
ReleaseCachedFileHandlesCalling this function will release file handles internally cached by Unity. This allows modifying asset or meta files safely thus avoiding potential file sharing IO errors.
RemoveAssetBundleNameRemove the AssetBundle name from the Asset Database.
RemoveObjectFromAssetRemoves object from its asset (Additional Resources: AssetDatabase.AddObjectToAsset).
RemoveScriptableObjectsWithMissingScriptRemoves any ScriptableObject instances from the given asset file which cannot be loaded because their scripts could not be found.
RemoveUnusedAssetBundleNamesRemove all the unused AssetBundle names in the Asset Database.
RenameAssetRename an asset file.
ResetCacheServerReconnectTimerResets the internal cache server connection reconnect timer values. The default delay timer value is 1 second, and the max delay value is 5 minutes. Everytime a connection attempt fails it will double the delay timer value, until a maximum time of the max value.
SaveAssetIfDirtyWrites all unsaved changes to the specified asset to disk.
SaveAssetsWrites all unsaved asset changes to disk.
SetImporterOverrideSets a specific importer to use for the asset.
SetLabelsReplaces the list of labels on an asset.
SetMainObjectSpecifies which object in the asset file should become the main object after the next import.
StartAssetEditingPauses automatic asset import, allowing you to group several asset imports together into one larger import.
StopAssetEditingEnds the Asset Database's temporary paused state, allowing it to resume normal automatic imports.
TryGetAssetFolderInfoGet AssetDatabase specific information about a folder.
TryGetGUIDAndLocalFileIdentifierGet the GUID and local file id from an object instance id.
UnregisterCustomDependencyPrefixFilterRemoves custom dependencies that match the prefixFilter.
ValidateMoveAssetChecks if an asset file can be moved from one folder to another. (Without actually moving the file).
WriteImportSettingsIfDirtyWrites the import settings to disk.

Static Events

Member

Description

cacheServerConnectionChangedUnity raises this event when Cache Server connection is changed.
importPackageCancelledCallback raised whenever a package import is cancelled by the user.
importPackageCompletedCallback raised whenever a package import successfully completes.
importPackageFailedCallback raised whenever a package import failed.
importPackageStartedCallback raised whenever a package import starts.

Classes

Class

Description

AssetDatabase.AssetEditingScopePlaces the Asset Database into a state that temporarily prevents automatic import, allowing you to group several asset imports together into one larger import.

Enums

Enum

Description

AssetDatabase.RefreshImportModeOptions for controlling the Editor's use of parallel processes when it imports assets during an asset database refresh.

Delegates

Delegate

Description

AssetDatabase.ImportPackageCallbackDelegate to be called from AssetDatabase.ImportPackage callbacks.
AssetDatabase.ImportPackageFailedCallbackDelegate to be called from AssetDatabase.ImportPackage callbacks.