I can't set the rect_position of a ColorRect.

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

Hello, I’m trying to implement a drag and drop feature using Godot 4.

This is my code:

func _process(delta):
if dragging:
	$ColorRect.rect_position = get_viewport().get_mouse_position()

(The formatting is messed up here, but I can’t get it right :/)

When i run it i get this error:
Invalid set index 'rect_position' (on base: 'ColorRect') with value of type 'Vector2'.

:bust_in_silhouette: Reply From: jgodfrey

Your code is likely valid in 3.5. For instance, this works in 3.5:

func _process(delta):
	$ColorRect2.rect_position = get_global_mouse_position()

However, as documented for 4.0, there is no longer a rect_position property. While I don’t have 4.0 installed, it seems to be named position now. So, I’d expect this to work:

func _process(delta):
	$ColorRect2.position = get_global_mouse_position()