TextureImporter to Sprite

I would like to be able to generate an outline mesh automatically when dragging an image to the editor.
Like this example:

I know that with this code, placing it inside an editor folder I can change the settings of the image when importing it.

public class SpriteImporterTool : AssetPostprocessor
{
	void OnPreprocessTexture()
	{
		TextureImporter texture_importer = (TextureImporter)assetImporter;

		texture_importer.textureType = TextureImporterType.Sprite;
		texture_importer.filterMode = FilterMode.Point;
		texture_importer.wrapMode = TextureWrapMode.Clamp;
		texture_importer.mipmapEnabled = false;
		texture_importer.spritePixelsPerUnit = 100;

		TextureImporterSettings texture_settings = new TextureImporterSettings();
		texture_importer.ReadTextureSettings(texture_settings);
		texture_settings.spriteMeshType = SpriteMeshType.Tight;
		texture_settings.textureShape = TextureImporterShape.Texture2D;
		texture_importer.SetTextureSettings(texture_settings);
	}

I also know that Sprite has a member function call OverrideGeometry which allows to change that outline geometry. I just do not know how to access that sprite when importing.

Thanks :slight_smile:

Well, the geometry override was in order to have shadows to the sprites. Just happens that having a shader was way easier and better for performance. I ended up in this hole because I initially had some problems with creating that shader in HDRP. But I manage to solve them at the end.

In case you still want to change the geometry while importing. I noticed the png.meta has the outline saved there. Right after the file is created you could change that. Maybe not the right approach but it should work.

For those who got here wanting the same as I did, here is the shader and material.


168316-material.png