0 votes

In this basic scene, I'm finding that my Area2d no longer fires the CollisionObject2d.input_event as soon as I add a ColorRect to the scene.

Scene Structure
(Image preview doesnt seem to work - the URL is https://imgur.com/a/HItl3Qo )

So there's:

--> Node2d (root)
----> Area2d
------> CollisionShape2d
------> Sprite
----> ColorRect

I have a script on my ClickableArea2d which is hooked up to the input_event, so that when clicked, it prints to the console.

public void _on_ClickableArea2D_input_event(Viewport viewport, InputEvent inputEvent, Shape shape)
{
    if (inputEvent is InputEventMouseButton mouseButton && mouseButton.Pressed)
    {
        GD.Print("Clicked");
    }
}

If I toggle visibility off on my BackgroundColorRect off, my ClickableArea2d's input_event fires and the message is logged to the console. However If I toggle visibility of the color rect back on, my clicks are no longer detected.

Can anyone suggest why this is happening, and how I might fix it? I essentially want the BackgroundColorRec as a background only and not to intercept any clicks.


Edit

After some more searching, I found this helpful SO answer which explains the solution:

In the ColorRect, there is a "Mouse" section. Originally it was set to "stop". Change it to "Ignore" fixes the issue

Godot version v3.4.4 mono
in Engine by (12 points)

1 Answer

0 votes

Yeah, ColorRect and GUI elements in particular (generally) get placed "on top" of the scene since they're drawn last (though some SceneTree manipulation helps). Sounds like you solved it though.

If it's not a GUI screen specifically, turn that Mouse filter off.

by (548 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.