Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input does not seem to receive events from an InputSender #578

Open
Kulkodar opened this issue Mar 11, 2024 · 6 comments · May be fixed by #587
Open

Input does not seem to receive events from an InputSender #578

Kulkodar opened this issue Mar 11, 2024 · 6 comments · May be fixed by #587
Labels

Comments

@Kulkodar
Copy link

Kulkodar commented Mar 11, 2024

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

@bitwes bitwes added the bug label Mar 20, 2024
@bitwes
Copy link
Owner

bitwes commented Mar 20, 2024

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.

@bitwes
Copy link
Owner

bitwes commented Mar 20, 2024

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

@lxkarp
Copy link

lxkarp commented Apr 2, 2024

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.

@bitwes
Copy link
Owner

bitwes commented Apr 2, 2024

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

lxkarp pushed a commit to lxkarp/Gut that referenced this issue Apr 3, 2024
@lxkarp lxkarp linked a pull request Apr 3, 2024 that will close this issue
@ArSn
Copy link

ArSn commented Apr 14, 2024

(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. 🙇🏻‍♂️

@bitwes
Copy link
Owner

bitwes commented Apr 22, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants