How to get the actual size of a game object?

First, I have already searched many questions and answers. But none of them answer my question. So I create this new one.

I have a sprite sheet file created by TexturePacker. The sprite sheet contains a image as below, you can see, it displays as 31x40 pixels in the Unity editor. But the original image is 64x64 pixels (the bottom one).
57471-gg.png

When I try to access the position of game object which is created by the sprite. The strange thing happens, its position (tranform.position, I create a small purple circle there) is not located on the actual centre of the sprite, but on a bigger rect’s centre position. The game object’s rect seems to be 64x64, not 31x40.
57472-in-world.png

So, how can I get the actual width/height(64x64) of the game object, instead of the displayed width/height(31x40)?

BTW, can I move the centre position to the correct one?

Or, can I change the game object’s size to correct one(31x40)?

Many thanks!

Okay, I figure out the reason…

The latest version of TexturePacker(v3.9.4) has a setting called “Trim Mode”. That will change the sprites’ size and layout position. Its default value is “Crop, keep position”.

After you generated the sprite sheet by TexturePacker and import it. The sprites inside the sprite sheet will have a “custom pivot” setting in the Unity Sprite Editor, instead of the default value (0.5, 0.5).

It will make the transform.position of the game object is not on centre, but on a custom position. So, if you want to make the position behavior normally, you should choose the Trim Mode as “None” or “Crop, flush position”, then problem solved. :slight_smile:

Hi,

Yes you can move the center position: it’s the pivot of your sprite in the Sprite Editor window (where you defined the actual size of your sprite). And there is no such thing as “The game object’s rect”. The game object only knows it’s position :slight_smile: