Search Unity

obj.GetComponent<SpriteRenderer>().sprite.bounds.size unpridictable results

Discussion in '2D' started by razerblood17, Jul 23, 2016.

  1. razerblood17

    razerblood17

    Joined:
    Jul 12, 2012
    Posts:
    3
    Hello im trying to get the the size of an sprite that i instantiated. The problem is that using obj.GetComponent<SpriteRenderer>().sprite.bounds.size will change when i move my main camera to a different world coordinate (some times it will be negative? why? im also applying camera.WorldToScreenPoint(); to the values in pixels before i debug them). How do i get the concrete rendered size of a sprite?
     
  2. unitynoob24

    unitynoob24

    Joined:
    Dec 27, 2014
    Posts:
    398
    Are you changing the size of the sprite at all during game play?
     
  3. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    You're gonna need to share the code you're using to get the values. Sprite.bounds.size is the concrete size of the sprite. The only time bounds will be incorrect will be before the object is initialized. Bounds size cannot be equal to or less than 0, so the problem is in your code.