I’m trying to generate a number of PNG icons from 3d objects in Unity. Generating and saving the images works fine, but I can’t seem to finish the process of saving the new assets to the database. When I attempt to use
AssetDatabase.ImportAsset(), it fails with the following error:
Could not create asset from Assets/Artwork/Resources/Icons/Insertions/Carnation - Light Blue.png: Texture could not be created. UnityEditor.AssetDatabase:ImportAsset(String, ImportAssetOptions) Editor.IconGenerator:SaveTextureToPNG(String, Texture2D) (at Assets/Code/Editor/IconGenerator.cs:95) Editor.IconGenerator:GenerateInsertionIcons() (at Assets/Code/Editor/IconGenerator.cs:38) Editor.IconGenerator:GenerateAllIcons() (at Assets/Code/Editor/IconGenerator.cs:17)
That path is directly from a previous reference to the asset, so I don’t understand why it fails. When I check in the inspector, the new assets exist, and the settings are actually changed, but they haven’t been applied.
Here’s a snippet of the larger script:
TextureImporterSettings settings = new TextureImporterSettings(); settings.alphaIsTransparency = true; settings.alphaSource = TextureImporterAlphaSource.FromInput; settings.sRGBTexture = true; textureImporter.SetTextureSettings(settings); EditorUtility.SetDirty(textureImporter); AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate);