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.
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.