0 votes

I put an empty TextureRect in an empty HBoxContainer. Gave it a 64*64 sprite, then the height of the HBoxContainer became 64 automatically. I set the Scale of the TextureRect smaller (0.5*0.5) since it felt too big, but this time the height of the Container did not change (stayed at 64). Moreover, the height cannot be fixed manually in the editor.

I guess it is because the Size of the TextureRect is still 64*64. However, this Size cannot be changed in the editor either (as far as I know).

What is the best way to resize the TextureRect? Is it inevitable to resize the original sprite outside Godot?

Godot version 3.5.1
in Engine by (46 points)
edited by

1 Answer

+2 votes
Best answer

BoxContainer controls size of its childrens. This is why you can't directly manipulate with size of TextureRect inside box container. To resize TextureRect inside box container, you need to do next things with your TextureRect:
1. Turn on expand checkbox in TextureRect section. Now your sprite will disappear (note that it's size became 0). This checkbox allows your textures to be lesser than basic size.
2. Set desired size using Min Size property (x for width, y for height) in Rect section. After this step your sprite might get stretched. If so, do third step.
3. Disable fill flag for required orientation(s) in Size Flags section.

by (1,650 points)
selected by

Thank you so much for your detailed answer! It saved me a lot of time.
Turning on expand makes the size.x of the texture be 0. Could you tell me why it does not become the full rectangle of the Container? (For me it is what "expand" should does.)

Current name of the property is quite misleading, this is probably why it got renamed to "Ignore Texture Size" in Godot 4. According to docs, Expand tells engine to "scale texture to fit its bounding rectangle". So, if your rectangle is smaller than sprite's resolution, it "fits" it into bounding rectangle, making actual sprite size smaller.

Thank you again. "Ignore Texture Size" sounds more natural for me!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.