Hello, I would like to configure a sprite in multiple mode on runtime by this way: Code (CSharp): public void ConfigTexture() { TextureImporter importer = TextureImporter.GetAtPath("Assets/Resources/idle.png") as TextureImporter; importer.textureType = TextureImporterType.Advanced; importer.maxTextureSize = 2048; importer.textureFormat = TextureImporterFormat.AutomaticTruecolor; importer.isReadable = true; importer.filterMode = FilterMode.Bilinear; importer.npotScale = TextureImporterNPOTScale.None; importer.wrapMode = TextureWrapMode.Clamp; importer.mipmapEnabled = false; importer.spriteImportMode = SpriteImportMode.Multiple; UnityEngine.Object asset = AssetDatabase.LoadAssetAtPath(importer.assetPath, typeof(Texture2D)); if (asset) { EditorUtility.SetDirty(asset); } else { importer.textureType = TextureImporterType.Advanced; } } The problem is, the asset in Resource folder look like Texture2D not a multiple Sprite with left arrow who permit to see sprites. How can I configure an image to a sprite properly in runtime ? Thank you.
I found it! I added this : Code (CSharp): AssetDatabase.ImportAsset(importer.assetPath, ImportAssetOptions.ForceUpdate); complete code if anybody want to use it : Code (CSharp): public void ConfigTexture() { TextureImporter importer = TextureImporter.GetAtPath("Assets/Resources/idle.png") as TextureImporter; importer.textureType = TextureImporterType.Advanced; importer.maxTextureSize = 2048; importer.textureFormat = TextureImporterFormat.AutomaticTruecolor; importer.isReadable = true; importer.filterMode = FilterMode.Bilinear; importer.npotScale = TextureImporterNPOTScale.None; importer.wrapMode = TextureWrapMode.Clamp; importer.mipmapEnabled = false; importer.spriteImportMode = SpriteImportMode.Multiple; UnityEngine.Object asset = AssetDatabase.LoadAssetAtPath(importer.assetPath, typeof(Texture2D)); AssetDatabase.ImportAsset(importer.assetPath, ImportAssetOptions.ForceUpdate); if (asset) { EditorUtility.SetDirty(asset); Debug.Log("dirty"); } else { importer.textureType = TextureImporterType.Advanced; Debug.Log("not dirty"); } } See ya
Hi I have an issue where the importer always comes back null even though the file is in the directory . Any suggestions? Also can it only run in Unity Editor script? or at normal run time as well?
I figured out my issue. I was using the full path to my asset when the path should be relative to your project.