The setter and getter functions for built-in objects don't work as I would expect. According to the docs the setter for position is
set_position(value)
the following code:
extends Node2D
func _ready():
self.position = Vector2(1, 1)
print(position)
# prints (1, 1)
func set_position(new_pos):
position = Vector2(0, 0)
prints (1, 1) as an output, while I would have expected (0, 0). Compare the above code to
extends Node2D
var my_pos: Vector2 setget set_my_pos
func _ready():
self.my_pos = Vector2(1, 1)
print(my_pos)
# prints (0, 0)
func set_my_pos(new_pos):
my_pos = Vector2(0, 0)
It seems in the built-in case the setter is not ever called when making the assignment, even when accessed externally. In other experiments, I had similar results for the built-in getter functions.
Obviously this isn't too hard to work around, but it is a bit confusing. Could someone please help me understand what's going on?