| Parameter | Description |
|---|---|
| path | Path to the asset. |
Texture A generic type icon for non-texture assets, and a small aspect-correct thumbnail for textures, or null if the asset has no icon.
Retrieves 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.
The icon is resolved from the Asset Database and reflects per-asset distinctions (custom MonoScript icons, open/closed folders, prefab type, importer-assigned icons). For textures it returns a small, aspect-correct thumbnail baked at import time (correct even for normal maps), not the raw texture. This is more efficient than AssetPreview.GetAssetPreview and is always available, but it is an icon lookup rather than a live render. For non-texture assets such as materials or models it returns a generic type icon rather than a rendered preview.
using System.Collections.Generic; using UnityEditor; using UnityEngine;
public class AssetDatabaseExamples : MonoBehaviour { [MenuItem("AssetDatabase/Get Cached Icon Example")] public static void GetCachedIconExample() { var textureList = new List<Texture>(); //Get asset icons and put them in a list foreach (var guid in AssetDatabase.FindAssets("", new []{"Assets"})) { var path = AssetDatabase.GUIDToAssetPath(guid); textureList.Add(AssetDatabase.GetCachedIcon(path)); }
//Set Material textures to the asset icons var textureNo = 0; for (var i = 0; i < 10; i++) { var path = $"Assets/Materials/GroundMaterial{i}.mat"; var asset = (Material)AssetDatabase.LoadMainAssetAtPath(path); if (textureNo >= textureList.Count) textureNo = 0; asset.mainTexture = textureList[textureNo++]; } } }