- Home /
Sprite.OverrideGeometry() doesn't work?
Hey Guys! I'm trying to set the geometry on a Sprite but I'm getting this error every time I try and run the function.
"Not allowed to override geometry on sprite 'squidward__handsome_squidward_by_millegas-d61zr7o' UnityEngine.Sprite:OverrideGeometry(Vector2[], UInt16[]) SkewTest:Update() (at Assets/ScriptResources/Testing/SkewTest.cs:22)"
and my code is:
Vector2[] m_MeshVerts = m_CurrentSprite.vertices;
ushort[] m_MeshTris = m_CurrentSprite.triangles;
m_CurrentSprite.OverrideGeometry(m_MeshVerts, m_MeshTris);
I've also found this description on the blog: "2D: Sprite geometry can now be overridden using Sprite.OverrideGeometry(Vector2[] vertices, UInt16[] triangles). Unity Pro only."
Does anyone know why I'm getting this error? I have Unity Pro.
Answer by ZimM · Apr 19, 2015 at 02:54 PM
Apparently, Sprite.OverrideGeometry()
only works when called as a part of texture import process. In other words, you can only call it from within AssetPostprocessor. OnPostprocessSprites(Texture2D texture, Sprite[] sprites)
or AssetPostProcessor.OnPostprocessAllAssets(...)
.
Well THAT sucks. How are we supposed to create triangle-mesh sprites at runtime?
This is not true for Unity 2017+, maybe event earlier versions (I'm currently on 2017.2.0f3, but I've been using it for a while now). You can run OverrideGeometry
during runtime (in my case, it's called in a Start
method). The only case where I found it not working is when the sprite you are trying to override is using FullRect as it's mesh type (in my case, the sprite is also created during runtime). Not sure if that's a bug or not though. Using Tight fixed the problem for me.
Your answer
![](https://koobas.hobune.stream/wayback/20220613193053im_/https://answers.unity.com/themes/thub/images/avi.jpg)