bitwes/Gut

Input does not seem to receive events from an InputSender

Kulkodar opened this issue · 6 comments

I'm not sure if the error is on my side or if there is a bug. When i try to test my scene that uses Input to query events in the _physics_process function, it always returns false or in the case of Input.get_vector a zero vector. I did follow the instructions found on the wiki.

If i missed any information that would help, please let me know.

OS: Linux
Godot version: 4.2.1
Gut version: 9.2.1
Example project: test.zip

This looks reasonable. I'm not sure if this is a bug or if this InputSender is being used in a way that I wasn't expecting. I'll look into it.

It looks like InputSender is missing a call to Input.action_press and Input.action_release when Input is a receiver. Right now, only _input(event) sees actions when using Input.

I was able to get your test to pass with this (which is what InputSender should be doing in addition to Input.parse_input_event):

func test_move_with_action_press():
	var player = Player.new()
	add_child_autofree(player)

	Input.action_press("move_backward")
	await wait_frames(5)
	
	assert_ne(player.test,Vector2(0,0))

Hey, @bitwes, I'm running into this bug as well. Do you have any advice for where to begin troubleshooting this issue? I've got a day or two to spend on it.

I think the fix is to change input_sender.gd @ line 279. Off the top of my head it would look something like:

		if(r == Input):
			Input.parse_input_event(event)
			# fix starts here
			if(event is InputEventAction):
				if(event.pressed):
					Input.action_press(event.action)
				else:
					Input.action_release(event.action)
			if(_auto_flush_input):
				Input.flush_buffered_events()

My approach would be to make a test script to reproduce the issue (probably test/unit/test_bugs/test_i578.gd or try to find the right place in test/unit/test_input_sender.gd). Try that fix, then tidy things up. If that fix works, it might be a candidate for a new method, that's a lot of indentation. It might also be good to move any tests in test_i578.gd over to test/unit/test_input_sender.gd (if you didn't just put the tests there in the first place).

ArSn commented

(Disclaimer: Godot newbie here, sorry if anything I say is dumb)

Just wanted to chime in to report that I also ran into this, thanks to the both of you for providing a fix!

@bitwes I went and step-debugged GUT for this and still did not find the issue. Reading the doc of Input.action_press, this fix makes sense, I do wonder however why Input.parse_input_event does not do the trick? The doc does not say anything about specific events not being applied. I'm mostly asking to figure out if I shoud open a PR to the Godot docs to add a note to that regard, so if you have any thoughts, I'd be thrilled to hear them!

Thanks again. 🙇🏻‍♂️

It seems that if you are using Input.is_action_pressed or Input.is_action_just_pressed you must also use Input.action_press/release when simulating input.

Note: This method will not cause any Node._input calls. It is intended to be used with is_action_pressed and is_action_just_pressed. If you want to simulate _input, use parse_input_event instead.

https://docs.godotengine.org/en/stable/classes/class_input.html#class-input-method-action-press