Hey,
I want to load an asset from script, but is there a way to look for the asset in the same folder of the script or a sub folder, so that the asset can be moved without relying on a path to look for?
Right now i’m using AssetDatabase.LoadAssetAtPath, i don’t want to use the resource folder.
Thanks
There are several ways how this can be done.
Editor Resources Folder
If you create a resources folder inside an editor folder those resources will only be available to editor scripts. You would use EditorGUIUtility.Load to load resources from such a folder. Just like the runtime resources folder the required path is relative to the resources folder. So it doesn’t matter where the folder is located as long as the path within the resources folder stays the same. See Special Folders for some more information.
Relative path
Another way could be to figure out the location of the actual editor script. Most editor classes are actually ScriptableObjects (Editor, EditorWindow, …). The usual event order would be something like:
I went with Bunny83’s suggestion and used a Resources folder inside my Editor folder and used this line of code to get the texture:
texture = Resources.Load("Testicon") as Texture2D;