How can I resize a TextureRect in GDScript?

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

I want to change the Image on a TextureRect, change the size (or scale) of it and center it, I’ve been trying with:

$TR.texture = texture2
$TR.set_size(Vector2(600,600))
$TR.set_anchors_and_margins_preset(PRESET_CENTER)

and the event

func _input_event():

but I don’t get how to use them correctly. Sometimes I get the new size but the image doesn’t change when I put $TR.texture = texture2 inside of the event function