Topic was automatically imported from the old Question2Answer platform.
Asked By
DigitalDrako
The title says it pretty well, I need to be able to hover over a button in my project but not press it when it’s in this state. Is this possible in godot?
This is possible, but it’s harder than it should be. There’s something unexpected (to me) about how the _Input(InputEvent @event) function is called. It appears to be always called, even when it seems like another Control should have handled the event. To work around this I added a mouse cursor position check.
Add a script to your Button that tells Godot that the mouse pressed event has been handled. Example in C#:
public override void _Input(InputEvent @event) {
if(@event is InputEventMouseButton) {
InputEventMouseButton mouseEvent = @event as InputEventMouseButton;
if(mouseEvent.Pressed && GetGlobalRect().HasPoint(mouseEvent.GlobalPosition)) {
GetViewport().SetInputAsHandled();
}
}
}
Thanks for the help! I have 0 familiarity with C# though, aside from gdscript I’ve only ever used python and JS. Could you break down the logic for me, or do you know how much of this transfers to gdscript?