TextureGenerator.GenerateTexture sprite pivots are all Vector2.one * 0.5f

,

I’m trying to script an importer for sprite sheets that have both masks and normal maps. I’ve been able to get the secondary textures working by calling UnityEditor.Experimental.AssetImporters.TextureGenerator.GenerateTexture(), but it seems that no matter what I do, all the sprites that are generated have their pivot value set to their center.

The code I have currently looks a bit like this:

var settings = new TextureGenerationSettings(TextureImporterType.Sprite);
// ... a bunch of other settings

settings.textureImporterSettings.spritePivot = inspectorSettings.spritePivot;

Also, there doesn’t appear to be anyway to alter the sprite pivot on the Sprite object itself, and attempting to create an alternate version with Sprite.Create() breaks the relation with the normals and mask textures.

Is there some other way to set this or is this really broken?

[Edit: I’m using 2020.1.x of Unity]

On TextureGenerationSettings, there’s a field called spriteImportData. I suspect this is similar to SpriteMetaData[ ] spritesheet field found on the TextureImporter. If so, then for spritesheets you would assign a SpriteImportData[ ] to the settings. That struct has a field called pivot, which if like SpriteMetaData wants a relativized pivot, e.g. (.5f, .5f) would be centered in the middle of the sprite’s rect.

https://docs.unity3d.com/ScriptReference/Experimental.AssetImporters.SpriteImportData.html

Yep, i’m assigning that as well, it has all the sprite metadata, with the correct pivots, but the TextureGenerator doesn’t seem to respect it.

I figured out what I was doing that was causing the issue. In the SpriteImportData[ ] I was setting the spritePivot, but I wasn’t setting the alignment so it was defaulting to center. :sweat_smile:

Anyway, once I had that changed to use Custom alignment everything worked as expected.