- Home /
Creating assets from code: what does this error mean?
I'm creating Texture2D's and saving them as assets for later use with AssetDatabase. The first time I ran the code everything worked. I made some tweaks, deleted the old textures from the editor, and now I run it again and get this error:
Couldn't add object to asset file because the Texture2D 'tex_Cube' is already an asset at ''!
UnityEditor.AssetDatabase:AddObjectToAsset(Object, String)
ControllerEditor:OnInspectorGUI() (at Assets/Editor/ControllerEditor.cs:63)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
Which I'm not really sure what it means. As if the textures where saved at some empty path '', and now a Texture with the same name can't be saved. No idea, really! I am saving the assets like so:
string assetPath = "Assets/MyTextures/" + assetName + ".asset";
Texture2D tex = CreateMyTexture();
tex.name = "tex_Cube"; //for example
tex.Apply();
AssetDatabase.Refresh();
AssetDatabase.AddObjectToAsset(tex, assetPath);
AssetDatabase.SaveAssets();
Your answer
Follow this Question
Related Questions
When looping through assetbundle assetdatabase how do you reference a material object 0 Answers
Proper way to refresh asset 0 Answers
How to make a new path register in the AssetDatabase? 2 Answers
Custom assets give Missing (Mono Script) 0 Answers
editor scripting for setting mechanim statemachine layer avatarmask 0 Answers