Input action is not consistently activated when using is_action_pressed()

Godot Version

v3.5.2.stable.fedora [170ba337a]

Question

I tried following a tutorial, which instructed me to create an input action called ui_touch, that includes “All Devices, Left Button”. This is the function relating to the action:

func _on_input_event(_viewport, event, _shape_idx) -> void:
	if event.is_action_pressed("ui_touch"):
		print("ui_touch triggered")
		touch_down = true
		position_start = event.position

Unfortunately, when I test the scene, the action doesn’t get triggered every time I left-click. I added the print() to debug, and it indeed doesn’t print most of the time when I left-click. There doesn’t seem to be any rule regarding when it is triggered.

I’d love help. Thank you.

One thing to keep in mind is that I think ‘ui_touch’ is a editor input action. You should define your own as this could be set as “handled” by the input stack, or editor, and not propagate down to your collision shape.

If the input is not consumed by anyone else then a ray is cast from the camera into the scene and your collision shape must be big enough to collide readily with the ray.

You can turn on collision shape wires in the debugging menu to see where you should be clicking.

If there are other shapes that could be in the way you should remove the “ray pickable” option as you see fit.

So… rename the action? I’m a novice, this is a bit complicated for me.

Make a new one, go to the project settings and then to the input map tab and create a new action.

It could be possible that the built-in action is fine have you tried the other suggestions?

I deleted it and created an identical action with no ui_. The issue persists.

Is your collision shape (area, static or rigid body) ray pickable enabled?

Isn’t that only in 3D? I can’t find this property in CollisionShape2D.

Update: I see it is in 2D too, but you need a RayCast2D? I don’t have that, as the tutorial didn’t mention it.

Input pickable

The area/static/rigid/character body class would have it exposed in the inspector.

There are “camera rays” in 2d, they just work a little different but can be thought of the same way.

I was looking at 4.2 docs but 3.6 docs has the same thing.

1 Like

I think that’s where the problem lies: I’m using CollisionShape2D, not CollisionObject.

Update: Just realized its parent node is Area2D, which inherits CollisionObject2D. It has the input pickable option turned on.

A collision object requires a collision shape. There is no way else to use the shape without an object.

I guess looking at your input event code you may need to change how it is accessed.