Why Is there no concept of an Event?

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

I’m a business developer. I don’t think in scenes. I think in terms of objects and inheritance.

I was surprised that Godot globally handles all events on all objects. Even the 2D Buttons do not limit themselves to clicks just within their rectangle. A single mouse click being handled by each object, even when the mouse is not in the rectangle for the object.

Instead, it seems I have to calculate for every object in my application whether or not a particular click was meant for it or not. Meaning, I gain nothing from having Buttons vs Node2D, and meaning I have to a lot of low level work, things I would reject from any business developer. (In principle, if it seems like you’re doing too much work, either you or the system is broken.)

If there’s a better way, I’d like to learn, because I do appreciate being able to export to Android from this platform.

“and meaning I have to a lot of low level work” - you don’t have a lot of low level work, quite the opposite - Godot is the clearest and easiest one in that concern. If you attach a script in a Button, for example, you will catch only the events from that Button and its sub nodes, and only the events that you want. Also, have you looked at Signals?

alfredbaudisch | 2019-03-31 18:53

signals will definitely help me with the next issue I will face. I appreciate the direction.

At the moment, I have 19 card items when I start my application. Each one inherits from my card scene with an attached script. The _input responds even when I click on empty space. So, I tried adding a Button to the scene and moving the _input to the Button, except, as mentioned, the script responds to all events that the application does, and worse it fires 19 times (once for each card scene on the table.)

Again, you’re right, I will later want to signal a specific clicked or tapped/touched card to the main scene. But for now, my issue is that since the click isn’t handled the way HTML (for example) would, I have to calculate if my mouse was in the scene, the location of my relative scene to the root, the mouse coordinates, the bounds of my scene, whether two scenes might have received the click I wanted, etc.

This is all doable but cumbersome, and by virtue of being cumbersome, it means either I am doing something really stupid (which I hope to learn from) or else that this platform is not right for my needs.

Thank you

grendahl06 | 2019-03-31 19:07

“I have to calculate if my mouse was in the scene, the location of my relative scene to the root, the mouse coordinates, the bounds of my scene” - not at all! It is as simply as connecting the on_pressed signal for a given button, for example. Just click HTML onClick :slight_smile: Do like this: add a Button or TextureButton → click its node → the in the inspector go to the Node tab → double click the pressed() signal → assign a function. Done. Maybe even easier than HTML? :slight_smile:

alfredbaudisch | 2019-03-31 19:13

If you’ll add this as an answer, I will mark it as answered. I’m very spoiled by the reflection in Visual Studio, but when I had to switch to GD script (or thought I had to?), I lost the useful intellisense. Godot is picky about when it will and won’t show me help. I’ve been using the _input, expecting this was the only way objects handled input events. I’m still bothered that this assumption wasn’t right, but at least you’ve solved my current and next design blocks. Thanks.

grendahl06 | 2019-03-31 19:34

:bust_in_silhouette: Reply From: kidscancode

Godot is all about objects and inheritance, so you should feel right at home. “Scene” is just an organizational concept.

There are many ways in which a game may need to process inputs: gui inputs, actions, etc. InputEvent is your “event” you’re looking for.

As for what processes it, “everything” doesn’t receive a click unless you want it to. For example, if you don’t override _input() on a particular node, it’s not going to receive any input events. There are GUI (Control) nodes which can intercept events and not propagate them, or pass them along.

Have a look at the flowchart here: InputEvent introduction. Input events can be consumed by objects and not propagated to others in with whatever priority you may need.

There are lots of differences between Node2D and Button. The latter is a Control node, so it includes GUI-related styling, scaling, and input methods. A Node2D can be configured to capture inputs, because you might want to click on game objects or control a character.

Games have a lot of unique needs versus a typical business application. It may be a different system than you are familiar with, but I would suggest you try and approach it with an open mind before assuming it’s “broken”.

If you want to get at it, any comments about being broken need to be confined to the Buttons in the 2D engine. I have no comment on how game devs want to have all objects listen to all events, it’s weird to me but may work for you.

In the real world, where we model our virtual behaviors, my Blue Ray player does not listen to me walking around the house and does not randomly respond when I change shirts. Again, my blender doesn’t turn on when I start my car.

Our programming expectations are based on the common metaphors and behaviors of real world items.

I don’t mind that a Node2D should listen to all events. It’s a very low level object. A Button, however, should only react when I Hover, Click, Touch, DoubleClick on it. This is fundamental whether we’re talking about HTML and JavaScript or any of the high level languages.

Again, I’m sure Godot is great for games. I’m not here to rag on it, I’m here to use it. However, I’m also here to evaluate whether its worth my time; and if I have to program every little thing, then there’s no advantage to using an engine.

grendahl06 | 2019-03-31 17:55

I’m not sure what you’re talking about. Have you tried using a Button? Add a Button to your scene. Run it. Is it possible to interact with the button other than clicking, touching, or hovering on it? No.

kidscancode | 2019-03-31 18:09

sorry, I ought to have put in all caps “ON IT”. The Button responds even when I use these events on other scenes in the root. As mentioned above in the other comment section, this means my script responds 19 times to one click, NO MATTER WHERE I CLICK WITH THE ROOT. (I don’t normally use all caps, but I want the issue I’m having not to be confused for one I’m not having.) Thanks

grendahl06 | 2019-03-31 19:10

That sounds like something is configured very wrong. The Button signal only fires once, so is it possible you have it connected to multiple other nodes? Can you share your script/setup?

kidscancode | 2019-03-31 19:13

in this case, I’m not sure what to share. I have a main scene, this contains 4 player scenes, the player scenes have 3 cards, the card scene has the script. (I’ve left out 5 card items, if anyone is counting…which means I miscounted earlier.) Either way, the card script inherits from Node2D and has a _input function. This fires for every InputEvent, which I can discriminate to “if event is InputEventMouseButton” (or similarly when exporting to Android to use a ScreenTouch), however, this fires for all button presses anywhere in the root scene, even though this only attached in the Card sub-scene.

grendahl06 | 2019-03-31 19:26

Well, yes, as documented in the link I gave earlier, if you implement _input() on a node, you’re specifically telling it you want it to respond to all inputs - input() is the first option in that flowchart. If you used _unhandled_input() they they wouldn’t see the input on the Button, because it would have already been processed and not propagated further.

However, if you want the cards to only respond when they are clicked, you should make them Area2D nodes, which specifically define regions and can capture events using CollisionObject2D.input_event.

kidscancode | 2019-03-31 19:33

changed my vote. This isn’t the answer I was looking for; but I thoroughly appreciate your time. Also, I readily concede you answered the question I didn’t know I should have asked.

grendahl06 | 2019-03-31 19:38

No problem. Sometimes it’s hard to zero in on the issue when you’re coming at it from opposite directions. Best of luck moving forward.

kidscancode | 2019-03-31 19:40

I just wanted to point to _gui_input(). That is the override you’re probably searching when you only want to receive events which happen in the scrope of that very control.

wombatstampede | 2019-04-01 07:14