Only half Area2D registers mouse enter/exit behavior?

4.4.1 Stable

I have an Area2D with a CollisionShape2D.
The shape is a CircleShape2D.
I am taking advantage of the mouse entered/exited signals on the Area2D.
It will be used to define an area the player can click to set their rotation.

At least it will if I can figure out why only half of the circle is recognizing when the mouse enters the shape.

I’m testing this by printing “mouse over rotation” when the mouse enters and “mouse exit rotation” when the mouse exits.

func _on_rotation_mouse_entered() -> void:
	print("mouse over rotation")
	mouse_over_rotation = true

func _on_rotation_mouse_exited() -> void:
	print("mouse exit rotation")
	mouse_over_rotation = false

Outside of a simple control node as the root of the scene, I do no use any control nodes that would be blocking the mouse.

I do have another Area2D that bisects my circle.

It is created via script on a Line2D which builds a series of CollsionPolygon2Ds to act as the collision shape for the line.

func _create_collision_shapes():
	# remove existing collision shapes
	for child in polyshape.get_children():
		child.queue_free()
	
	var polygons = Geometry2D.offset_polyline(points,5)

	for polygon in polygons:
		var collision_poly = CollisionPolygon2D.new()
		collision_poly.polygon = polygon
		polyshape.add_child(collision_poly)

It also make use of the mouse entered/exited signals.
I am assuming that is the cause of the problem, but I don’t understand why it basically removes half the circle.
I also don’t understand how to fix this.

I’ve spent a lot of time with the documentation, but I’ll admit my understanding of mouse events and these signals is not great.

I’ve tried:
Setting the Line2D’s Area2D as set_pickable(false) and set_monitoring(false).
I’ve also tried setting the Circle Area2D at a higher index, combined with get_viewport().set_physics_object_picking_sort(true)

So far nothing has worked. Any help would be appreciated.

This signal may also not be emitted if another CollisionObject2D is overlapping the CollisionObject2D in question.

I guess this could be the issue?

It doesn’t say that for the mouse_shape_entered() signal, so maybe that would work?

1 Like

Why are you using a Control node as the root of your scene? If you don’t need it change it to a Node or Node2D node instead.

The Control may be consuming the mouse events. You can check if the Control is consuming the event by clicking on the collision shape while the game is running and check the Misc tab in the Debugger dock. Check if Last Clicked Control field shows anything. If it does, set that control Control.mouse_filter to Ignore and repeat.

2 Likes

When I initially made the scene I was using control nodes for the player interface. Then I realized that I could not get everything I needed out of them for my purposes.

You were right. It was consuming the mouse event. Thank you! I didn’t know you could just change the root node type either.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.