Legacy Documentation: Version 4.5.0

Script language:

  • JS
  • C#
  • Boo
Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

AssetDatabase.FindAssets

static function FindAssets(filter: string): string[];
static string[] FindAssets(string filter);
static def FindAssets(filter as string) as string[]
static function FindAssets(filter: string, searchInFolders: string[]): string[];
static string[] FindAssets(string filter, string[] searchInFolders);
static def FindAssets(filter as string, searchInFolders as string[]) as string[]

Parameters

filterThe filter string can contain search data for: names, asset labels and types (class names). See description for more info.
searchInFoldersSpecifying one or more folders will limit the searching to these folders and their child folders (and is faster than searching all assets).

Description

Search the assetdatabase using a searchfilter string.

You can search for names, lables and types (classnames). 'name': filter assets by their filename (without extension). Words separated by whitespace becomes seperate name searches. Use quotes if two or more words should be considered one word. 'labels': Use the keyword 'l'. Filtering by more than one label will return assets if just one asset label is matched (OR'ed) 'types': Use the keyword 't'. Filtering by more than one type will return assets if just one type is matched (OR'ed). Types can be either builtin types e.g 'Texture2D' or user script class names. If all assets are wanted: use 'Object' as all assets derive from Object.

Searching is case insensitive Returns: a list of asset GUIDs Use AssetDatabase.GUIDToAssetPath to get assetpaths and e.g AssetDatabase.LoadAssetAtPath to load an asset.

@MenuItem("Test/FindAssetsUsingSearchFilter")
static function FindAssetsUsingSearchFilter () 
{
	// Find all assets labelled with 'concrete' : 
	var guids = AssetDatabase.FindAssets ("l:concrete", null);
	for (var guid in guids)
		Debug.Log (AssetDatabase.GUIDToAssetPath(guid));
	
	// Find all Texture2Ds that have 'co' in their filename, that are labelled with 'concrete' and 'architecture' and are placed in 'MyAwesomeProps' folder
	var guids2 = AssetDatabase.FindAssets ("co l:concrete l:architecture t:texture2D", ["Assets/MyAwesomeProps"]);
	for (var guid in guids2)
		Debug.Log (AssetDatabase.GUIDToAssetPath(guid));
}