Override sprite geometry of sprite generated at runtime

I have a lot of Sprites in my Game, therefore I collect their textures and pack them during runtime into a bigger texture atlas.

I then want replace the old spriteRenderers’ sprites by creating a new Sprite via Sprite.Create(...)

As a next step I need to override the sprite’s vertices and triangles using OverrideGeometry(verts,triangles)

But the catch seems to be that I can not override the geometry unless the sprite mode is SpriteImportMode.Polygon, which I can only set in the TextureImporterSettings.

But since I create my atlas at runtime and do not want to safe it to the disk I can not change these either.

Is there a way to override a sprite’s geometry from a sprite created at runtime?

Hey again, what’s the error that you get when you call Sprite.OverrideGeometry? This all seems to work with my little test in Unity 5.3.4p1 that displays half of the sprite in one triangle (put script on a GameObject with a SpriteRenderer and add a readable texture to the atlasTextures array in the Inspector):

using UnityEngine;
using System.Collections;

public class Test : MonoBehaviour {

	public Texture2D[] atlasTextures;

	// could make these public for debugging purposes
	public Rect[] rects;
	public Texture2D atlas;
	Sprite sprite;
	SpriteRenderer spriteRenderer;

	// Use this for initialization
	void Start () {

		spriteRenderer = GetComponent<SpriteRenderer>();

		if (!spriteRenderer)

		// pack textures
		atlas = new Texture2D(8192, 8192);
		rects = atlas.PackTextures(atlasTextures, 2, 8192);

		// create sprite using rects[0]
		Vector2 atlasSize = new Vector2(atlas.width, atlas.height);
		Rect spriteRect = new Rect(Vector2.Scale(rects[0].position, atlasSize), Vector2.Scale(rects[0].size, atlasSize));
		sprite = Sprite.Create(atlas, spriteRect, new Vector2(0.5f,0.5f));

		// create new shape for sprite using array of vertices
		Vector2[] vertices = new Vector2[3];

		vertices[0] = new Vector2(0,sprite.rect.size.y);
		vertices[1] = new Vector2(sprite.rect.size.x,0);
		vertices[2] = new Vector2(0,0);

		ushort[] triangles = new ushort[3];

		triangles[0] = 0;
		triangles[1] = 1;
		triangles[2] = 2;

		// set sprite vertices
		sprite.OverrideGeometry(vertices, triangles);

		// send new sprite to the sprite renderer
		spriteRenderer.sprite = sprite;