Search Unity

Feedback OverrideGeometry not working.

Discussion in 'General Graphics' started by georgeq, Sep 18, 2019.

  1. georgeq

    georgeq

    Joined:
    Mar 5, 2014
    Posts:
    662
    I'm trying to modify a sprite's geometry but whatever parameters I set, OverrideGeometry always throws this exception:

    Invalid vertex array. Some vertices are outside of the Sprite rectangle: (1358.000000, 579.000000).
    UnityEngine.Sprite:OverrideGeometry(Vector2[], UInt16[])

    To discard any errors on my algorithm, I modified it to make an exact copy of the original vertices and rectangle size, but even coping the original values causes the exception to be thrown.

    I did some research and found out this bug was found on Unity 2017.2.0p2,and it was reported to be fixed on 2018.2... however I'm using 2019.2, and still experiencing the same problem.

    However... the problem is that you need to handle two different metrics, this is a problem not because you need to do some calculations to make this function work, but because you if you do a simple A=B and then B=A you get an error, and that should not happen. The value returned by
    Sprite.vertices gives you world units while OverrideGeometry requires pixels. That inconsistency can be the source for lots frustration, complaints and errors.
     
    Last edited: Sep 19, 2019
  2. tfalmeida91

    tfalmeida91

    Joined:
    Aug 3, 2018
    Posts:
    8
    Hi!

    Even after reading this I'm still having problems dealing with the sprite vertices, and I always get this same error.

    Have you found any solutions?
     
  3. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,513
    Below answer correct. It's also a good idea to clamp within sprite.rect width/height to avoid potential error message.
     
    Last edited: Apr 4, 2021
  4. iJuan

    iJuan

    Joined:
    Jan 13, 2017
    Posts:
    6
    I've got the same error, took me a while to figure out it was because the negative values (due to world units).

    In case someone is having the same error, this is how you convert vertices from units to pixels
    Code (CSharp):
    1. Vector2[] verts = sprite.vertices;
    2. for (int i = 0; i < verts.Length; ++i)
    3.     verts[i] = (verts[i] * sprite.pixelsPerUnit) + sprite.pivot;
    4. sprite.OverrideGeometry(verts, sprite.triangles);
    5.