Rect2 'expand()' method not working?

Godot Version

4.3.stable

Question

Hello!
I have a pretty basic script that’s trying to make use of the expand() method:

var new_rect: Rect2i = Rect2i() # Rect should be initiated with a size of 0,0
new_rect.expand(Vector2i(15,15)) # Exanding rect to 15,15
print("Map rect: ", new_rect.size) # Is printing 0,0 for some reason

Am I missing something, or should the print line be outputting 15,15?
Obviously I’m attempting to use this in a more complex setting, but even this basic test script doesn’t work for me.

Any clue why the expand() function isn’t working as expected?
Thanks!

Hi!

I did that and it seems to work better!


extends Node2D

var rect: Rect2i = Rect2i() # Rect should be initiated with a size of 0,0


func _ready() -> void:
	var new_rect = rect.expand(Vector2i(15,15)) # Exanding rect to 15,15
	print("Map rect: ", new_rect.size)  # print the size of the rect copy

Oh thanks haha I didn’t notice it was returning another rect XD
I guess that’s what 5 hours of sleep will do to you

1 Like