How to get size of 2D node in pixels?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ddabrahim


I’m new to Godot.
I would like to get the width and height of a node in pixels using code but I can’t find a way to get this property. I was searching the forum, the docs and the web and seems like everyone mentioning how to get scale but I don’t need the scale (1:1) value.

I need the actual width and height in pixels of a Sprite or a Node2D node but I can’t figure out how to get it.

I would appreciate any help.


:bust_in_silhouette: Reply From: kidscancode

A Node2D does not have a size, it only represents a position/rotation/scale (ie transform), and does not have any visual representation.

To get the size of a Sprite, you look at its texture property:

var size = texture.get_size()

Thanks a lot. It worked :slight_smile:

ddabrahim | 2019-01-13 22:15

if it worked, would you select the answer please? so others looking for the same answer can reach the solution easily!:slight_smile:

p7f | 2019-01-13 23:28

It returns the actual size of the image, but not the size at which it is displayed in case it’s scaled. How could we get that information also?

AsP | 2021-04-08 09:27

If you use get_size() you can multiply that by the scale to get the current scaled size of the sprite

MrBundles | 2021-07-13 03:05