AssetDatabase Manual     Reference     Scripting  
Scripting > Editor Classes > AssetDatabase
AssetDatabase

An Interface for accessing assets and performing operations on assets.

Note: This is an editor class. To use it you have to place your script in Assets/Editor inside your project folder. Editor classes are in the UnityEditor namespace so for C# scripts you need to add "using UnityEditor;" at the beginning of the script.

Class Functions
Contains

Is object an asset?

IsMainAsset

Is asset a main asset in the project window?

GenerateUniqueAssetPath

Creates a new unique path for an asset.

StartAssetEditing

Begin Asset importing. This lets you group several asset imports together into one larger import.

StopAssetEditing

Stop Asset importing. This lets you group several asset imports together into one larger import.

ValidateMoveAsset

Checks if an asset file can be moved from one folder to another. (Without actually moving the file)

MoveAsset

Move an asset file from one folder to another.

RenameAsset

Rename an asset file.

MoveAssetToTrash

Moves the asset at path to the trash.

DeleteAsset

Deletes the asset file at path.

ImportAsset

Import asset at path.

CopyAsset

Duplicates the asset at path and stores it at newPath

CreateAsset

Creates a new asset at path.

AddObjectToAsset

Adds objectToAdd to an existing asset at path.

GetAssetPath

Returns the path name relative to the project folder where the asset is stored

LoadAssetAtPath

Returns the first asset object of type type at given path assetPath.

LoadMainAssetAtPath

Returns the main asset object at assetPath.

LoadAllAssetsAtPath

Returns an array of all asset objects at assetPath.

Refresh

Import any changed assets.

OpenAsset

Opens the asset with associated application.

AssetPathToGUID

Get the GUID for the asset at path

GUIDToAssetPath

Translate a GUID to its current asset path

SaveAssets

Writes all unsaved asset changes to disk.

GetCachedIcon

Retrieves an icon for the asset at the given asset path.

CompleteLabel

Returns all labels that match the given prefix.

SetLabels

Replaces that list of labels on an asset.

GetLabels

Returns all labels attached to a given asset.

ClearLabels

Removes all labels attached to an asset.

GetDependencies

Given an asset pathName, returns the list of all assets it depends on.

ExportPackage

Exports the assets identified by assetPathNames to a unitypackage file in fileName.

ImportPackage

Imports package at packagePath into the current project.