Tweening rect_size.y of control not working (but rect_size.x is okay)

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

I’m working on a simple application that shows a list of controls. When a new control gets added to the list I want to make it look like it grows vertically. I created a tween for rect_size.y but it doesn’t work.

Tweening rect_size.x works just fine but when I try to make it grow/shrink vertically it doesn’t do anything.

I assume it could be because the items get added to a VBoxContainer and the container somehow prevents changing the height of the items.

Is there anything I can do to make this work?

Here is the my tweening function, it gets called when the control enters the scene

func grow():
	in_tween.interpolate_property(self, "rect_size:y", 0 , rect_size.y, 1.5, Tween.TRANS_LINEAR, Tween.EASE_OUT)
	var end_color = Color(1.0, 1.0, 1.0, 1.0)
	var start_color = Color(1.0, 1.0, 1.0, 0.0)
	in_tween.interpolate_property(self, "modulate", start_color, end_color, 0.5, Tween.TRANS_LINEAR, Tween.EASE_IN)
	if not in_tween.is_active():

With the last two lines, you don’t start the tweening if one is already running. Could it be that you’re tween us already running for another node? Make sure the tweening is starting.

MrEliptik | 2021-03-25 22:54

I doubt that’s the case since it works when I chance rect_size.y to x and the color transition plays regardless.

Takiro | 2021-03-26 00:16

:bust_in_silhouette: Reply From: MrEliptik

Ok! I’ve tested in a small project and I think I’ve found an answer.

I put a label as a child of a VBoxContainer with a style to see it clearly. If I use your technique, which is tweening the size of the rect, from 0 to its original size, it only works in X. The tweening doesn’t work on size because inside a VBoxContainer you can’t directly change the y size of a node.

But if you tween the scale from 0 to 1, it works in x or y. The tweening is now:

in_tween.interpolate_property(self, "rect_scale:y", 0 , 1, 1.5, 

Correct me if I’m wrong but I think it gives the result you’re expecting!

Yes, it works. It looks a bit weird because the content gets distorted but it basically does what it should. I suspected it’s due to the parent being ha VBoxContainer. Thanks, i didn’t think of using scale.

Takiro | 2021-03-26 10:05