How does EditorGUIUtility.FindTexture() work?

Whatever I try it returns null. Could anyone produce a working example?

This is still true with 5.0, and the documentation on this is a joke…

On the meantime, if anyone needs to find a texture from the editor, this works :

(Texture2D)AssetDatabase.LoadMainAssetAtPath("Assets/yourPath/yourTexture.png");
1 Like

Please don’t ask me how it works, but I can tell you that it does work for Unity built-in icons. I haven’t tested it because I use the Default Editor Resources folder to load editor graphics via EditorGUIUtility.Load.

Texture tex = EditorGUIUtility.FindTexture("SceneAsset Icon");
        GUILayout.Button(tex);

I’d really like to know where to get all the names for those built-in icons. I’ve seen people load warning signs and Animator Mecanim icons, so I’m interested what else we could use. I really don’t like using my own graphics, if they don’t perfectly match the Unity style.

1 Like

Additional info for necro:

https://unitylist.com/p/5c3/Unity-editor-icons

(contains the Unity Icon reference list by name. And is updated frequently (its pointing at Unity ver. 2020.x as of 3/2022)

1 Like

In addition to this list of built-in resources, this method can also load any arbitrary texture asset from your assets folder. Note that the path is always relative to your project folder. So an absolute path does not work. So when you want to load an image that directly sits in your Assets folder, you simply use "assets/yourFileName.png". Note that it has to be an actual asset that has been imported by Unity and is registrated in the asset database.

The built-in resources are actually packed into built-in asset files called “unity editor resources”, “unity default resources”, “unity_builtin_extra” (any maybe others) which are located in your Unity installation path (Editor/Data/Resources/). Those are ordinary binary asset files. In case the list of built in assets which was posted by KenAtGlu goes offline or becomes outdated, you can find all those built-in assets in those files. You could even copy the file into a project (add the extension .asset) and let Unity convert it into a text serialized asset file (which would probably double the size). However now you can even open it with a text editor and grab all the asset names.

Note that the built-in assets are part of the editor and are not meant for distribution. They belong to the Unity editor itself, so do not ship them with your game.

1 Like

I tried this out of curiousity and got this interesting result:

8011574--1031018--upload_2022-4-1_9-50-56.png
Unity successfully converts the binary to text YAML, but the content doesn’t represent any specific known asset type, so Unity apparently auto-detects the main asset type from the content somehow and just designates e.g the last one as material. Of course it makes sense because those files are most likely something similar to AssetBundles, packed collections of Unity objects.

Parsing those text files seems somewhat difficult because they are a couple of hundred megabytes large und we don’t know the structure. At first glance it looks like there isn’t much hierarchy going on, just a flat list of resources, not sure how to know which textures are icons, for example and which are other regular textures. But could be an interesting fun project.

Another way of discovering the names is within the Unity editor while its running. For example, you can look for a specific icon and find it visually somewhere in the editor GUI. Now we know that it must be loaded into memory, so we can use the Profiler and take a memory snapshot or write a quick script that uses Resources.FindObjectsOfTypeAll to simply show everything that is currently loaded in an editor window with a preview image.

Uhm, there’s an arrow to the left which you can expand just like any other asset file which contains multiple assets. I tried it with the unity editor resources and I can expand it and get a loooong list of all assets. This even includes the default meshes for the cube, plane, cylinder, etc…

:smile: I wasn’t able to expand because my editor froze, but sounds helpful!