Search Unity

SpriteRenderer.sprite.bounds not retrieving world values.

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

  1. georgeq

    georgeq

    Joined:
    Mar 5, 2014
    Posts:
    662
    I have two scripts that instantiate prefabs, in both of them I'm using SpriteRenderer.sprite.bounds to retrieve the world space size of the sprites, also in both cases the sprites have some rotation applied. One of the scripts is giving me the bounding box of the rotated sprite, which is what I want. The second script gives me the bounding box of the sprite without the rotation, and I can't understand why. There are two differences that I think should not affect.

    The first prefab has only one SpriteRenderer, and the rotation is applied through code just before retrieving the boundaries, in this case I get the correct result. The second prefab contains several SpriteRenderers, which's rotations are defined directly in the prefab's transforms, so theoretically those rotations are applied automatically as part of the instantiation process, but in this case I'm getting the boundaries as if all rotations were set to 0,0,0, which is not the case.

    I have no idea why this is happening. (Unity 2019.2.3f1)
     
    Last edited: Sep 19, 2019
  2. georgeq

    georgeq

    Joined:
    Mar 5, 2014
    Posts:
    662
    My mistake... I was using SpriteRenderer.bounds in the first script and SpriteRenderer.sprite.bounds on the second.