Area2D mouse_entered signal not working if ParallaxLayer visible

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

I have an Area2D with child node CollisionShape2D with shape RectangleShape2D. For some reason, the the mouse_entered signal is only sent out when I have all ParallaxLayers hidden. The Area2D is below the layers in the hierarchy. I tried changing the z-index but it didn’t work. How do I get the mouse_entered signal to work without hiding the background?

What is the order of nodes in scene tree?
Is Area2D above or below the parallax layers?

gioele | 2020-08-27 22:07

Here, let me quote that for you.

The Area2D is below the layers in the hierarchy.

Ertain | 2020-08-27 23:25

My bad, I couldn’t see that.

Anyway I made some tests and with Area2D as lowest node it seems to work, maybe it is necessary to check the parenting of the node.

  • Node
  • ParallaxBackground
    • ParallaxLayer1
    • ParallaxLayerN
  • Area2D
    • CollisionShape

This works for me, but maybe your scene is more complex than this.

gioele | 2020-08-28 07:17

Nope, that’s how my scene is set up too.

exuin | 2020-08-29 06:21

I see. If any other detail comes to your mind, please share as it may help in finding a solution.

gioele | 2020-08-29 08:05

Maybe I should be more specific.
I’m trying to get a parallax background to scroll when I move my mouse to the edge of the screen, so I have two area2ds on either side of the screen.
The layout looks like this:

  • Node2D
  • ParallaxBackground
    • ParallaxLayer
      • TextureRect
  • CanvasLayer (so the Area2Ds don’t move with the background)
    • Area2D
      • CollisionShape2D
  • Camera2D

I have a script on the Camera2D that is connected to the mouse entered and mouse exited signals on the area2ds.
For some reason, when I first play the scene, the signals don’t seem to work. But I also have the Camera set to scroll with keyboard inputs. So if I use the keyboard inputs to scroll the camera, the signals work. But only the Area2D on the right of the screen scrolls the camera, even though the code for scrolling the screen to the left and the right is the same. Also the mouse exited signal for the left Area2D is sent out right after the mouse entered signal even if I haven’t actually moved my mouse out of the area.

I’m really confused.

exuin | 2020-08-29 18:41

:bust_in_silhouette: Reply From: exuin

Turns out the TextureRects were eating the mouse events. Set the mouse filter to ignore to fix this.

Thanks self, great answer

exuin | 2020-10-05 03:51