_input and _unhandled_input working but _input_event is not

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

Good day!

I am using Godot 3.2.3stable.official and running into an oddity.

I can replicate it creating a brand new project. I add my top level node as Spatial (3d), add a MeshInstance, give it any shape, add a StaticBody to that, add a CollisionShape to that and add a shape to the collision. I tested with base cube/cylinder etc, some for shape and tried convex/concave colliders and always run into the same thing.

Adding this script to the StaticBody:

extends StaticBody


func _input(event):
	if event is InputEventMouseButton:
		print("input")

func _input_event(camera, event, click_position, click_normal, shape_idx):
	if event is InputEventMouseButton:
		print("input event")

func _unhandled_input(event):
	if event is InputEventMouseButton:
		print("unhandled event")

When I run my code and click on the mesh (or click anywhere for that matter) I get logs from input and unhandled but not from _input_event. I did verify the StaticBody has Input Ray Pickable enabled, which is the default.

I am sure I am doing something wrong, but I don’t see what. Any ideas on things to check?

Thanks!

Have you already read about how the inputs work?

Ertain | 2020-12-16 05:43

Thank you for the reply!

Yes, I have read over that and have no UI or anything else in my sample app that would be consuming the input, and I do have a camera on the viewport, so theoretically I should get an _input_event on my staticbody from what that link says.

For a bit more context, I downloaded the project from here: https://kidscancode.org/godot_recipes/3d/click_to_move/ which works but was recreating it from scratch. I have two things that are acting odd and I am sure they are related and something I missed but I have clicked on all of the nodes and see no differences in mine versus theirs. I have look at autoload, project settings etc but everything seems the same.

The two differences I see in mine versus theirs in my player (kinematicbody) falls through the ground, so that collision isnt working. I did not alter the collision layers or masks and they look the same as the tutorial. Also, clicking on the ground does not fire _input_event on the attached staticbody. These seem like they are of the same root cause but again, comparing node by node, file by file, settings etc, I see no differences between theirs and mine so I am unsure what I missed.

bot2600 | 2020-12-16 17:45

So I kind of figured this out. I turned on Visible Collision Shapes in the Debug menu and it some things I assumed were magic aren’t. :slight_smile:

The ground has a ConcavePolygonShape, and whilst my editor looks the same as theirs, there is some kind of configuration they must have done. The docs here: https://docs.godotengine.org/en/stable/classes/class_concavepolygonshape.html mention calling set_faces, but since I didnt see anything in their code doing so, the assumption was when you add it to a StaticBody that must happen for you. In their project if I clear the Shape type and then set it to ConcavePolygonShape again, their project is also broken, so it must need to set this somewhere but I haven’t a clue where.

A similar issue is plaguing my KinematicBody, it’s CollisionShape’s shape is a ConvexPolygonShape, which I also assumed would magically get filled in. With this one at least, I can break that guy open in their editor and see where the array was filled in, and if I fill it in by hand, it works.

For both of these, I assume the editor of this version for the Mac isn’t doing something it is supposed to be doing? I don’t see any documentation anywhere that this shouldn’t just work on its own, but I could be expecting too much :slight_smile: My next step is going to be to boot into windows and test the same sample project and see if the results are the same.

bot2600 | 2020-12-16 18:36

Same behavior in Windows, so I guess my expectations were just wrong, nothing to see here :slight_smile:

bot2600 | 2020-12-16 18:54

:bust_in_silhouette: Reply From: JeremiasDev

Hi, you have to do:

func _unhandled_input(event):
    if event is InputEventMouseButton:
        if event.button_index == BUTTON_LEFT:
            if event.pressed:
                print("Left button was clicked at ", event.position # show where you click)  
            else:
                print("Left button was released")