mouse_passthrough_polygon method couses my animated sprite to disappear

Godot Version

4.6.1

Question

Im trying to do one of those desktop pets to get familliar with Godot. I did some research and assigned Polygon2D to AnimatedSprite2D, turned on project settings (“transparency”, “borderless”, “pixel transparency,” “fullscreen”, “always on top“ and “transparent background”) and wrote this in my code:

func _ready() -> void:
	get_window().mouse_passthrough = false
	get_window().mouse_passthrough_polygon = $"Polygon2D".polygon

Upon running my project, window is fully transparent and i can click through it, but it also causes my sprite to completely disappear. I tried different solutions from youtube and this forum, but none of them worked for me.

Heres some solutions that i tried:

	var updated_polygon_array: PackedVector2Array = PackedVector2Array()
	for point: Vector2 in $"Polygon2D".polygon:
		updated_polygon_array.append(point * 3 + animated_sprite.global_position)
	print(updated_polygon_array)
	get_window().mouse_passthrough_polygon = updated_polygon_array

#Tried to put this code in _process() and ready() functions, both didn't work
func _process_clickables() -> void:
	var clickable_nodes = get_tree().get_nodes_in_group("Clickables")
	for node in clickable_nodes:
		if node in Control:
			var rect = node.get_rect() as Rect2
			var texture_corners: PackedVector2Array = [
				rect.position, #top left corner
				rect.position + Vector2(rect.size.x, 0), #top right corner
				rect.position + rect.size, #bottom right corner
				rect.position + Vector2(0, rect.size.y) #bottom left corner
			]
			DisplayServer.window_set_mouse_passthrough(texture_corners)
		else:
			printerr(node.name + " is not control")

#function is called in _process()

I would appreciate the help.

How do your polygon and sprite look like?

This piece of code looks correct, it should be put in the _process() function to update every frame. I’m not sure why you’re multiplying every polygon point by 3 though instead of just adjusting the original polygon size.

Instead of binding your polygon position to the sprite position, you can also bind it to the mouse position, maybe it’ll help you debug and match the polygon’s position with the sprite’s position. Like so:

updated_polygon_array.append(point + get_global_mouse_position())