How to get Assets path and to load an asset with out AssetsDatabase?

Hi!
I need to swap between a few different textures, and for this I have been using the AssetsDatabase.GetAssetPath to retrive the path of a current texture, and then used AssetsDatabase.LoadAssetFromPath to load the textures.
How ever I just found out that if your using AssetsDatabase then you need to reference the UnityEditor( using UnityEditor ) which doesnt compile during a build and causes errors.
Do I have any alternatives to the AssetsDatabase in this case?.. basically what I need to do is to get the path of a texture and then load a path/file as a texture.
Im currently doing this with C# as the lang of choice… but I guess that I could translate any js-script as well if needed :).

Thanks in advance!

I think you need to use the resources. load and tell the script the path directly. Unity - Scripting API: Resources.Load

You can use following code

Texture2D texture = Resources.Load(“aaa”) as Texture2D;

Maybe file extention doesn’t need.

And you should locate texture file(.jpg, .png etc.) in Assets/Resources folder.

You can find many reference about your question :slight_smile: