Input doesnt seem to be working at all

Godot Version

Godot 4.4

Question

This is my first project and I’m trying to detect input using Input.is_action_pressed(“ui_accept”) inside the _process function of an Area2D script, but it never triggers. I added a print statement and confirmed that _process is running, but the input condition is never true. I’m pressing Enter, but nothing happens. What could be causing this?

Here’s the script:
extends Area2D

var testVar = 0

func _process(delta):
if testVar == 0:
print(“_Process Triggered”) # Gets Triggered Immediately
testVar = 1
if Input.is_action_pressed(“ui_accept”):
print(“Enter Pressed”) # Never Triggered

It is not a great idea to put that in _process TBH. Do you really want to check if an input action was done every single frame? That is probably a lot of redundant checks.

Try this:

func _input(event) -> void:
	if event.is_action_pressed("ui_accept"):
		print("Enter button was pressed")

This will print whenever the enter button or space bar is pressed. It will react to an input rather than forcing a test for input 60 frames a second.

I notice you are using an Area2D. An input click might be being collected by another node in your tree. Firstly just create a new test scene, put this into it and run that. You should get the message printed whenever your press enter.

Hope that helps.

1 Like

but wouldnt it be better to check every frame for movement? and i still dont know why it just never activates the if statement

This works fine for me.

extends Area2D

func _process(delta: float) -> void:
	if Input.is_action_pressed("ui_accept"):
		print("Enter button was pressed")

Is this part of a bigger scene? Other parts of the scene may be collecting the input.

1 Like

Check the setting ‘Input’ on your Area2D, is pickable checked? It should be by default. Actually it should still work even if that was off as it is a keyboard input not a mouse click.

1 Like

after restarting godot to test the your solution my original code now suddenly works now with no changes, im even more confused now

1 Like

Well that is strange. I wonder what caused that peculiar behaviour. Anyway, at least it is working now!

1 Like

yea ty for the help

1 Like