I'm using Input.is_action_just_pressed(action name) and it randomly misses the event. I tried making my own latch with the _action_pressed method but having problems with that as well since I have to hold the button down until it reacts, which doesn't feel like a 'click' anyway.
Using godot 3.5 on Windows.
Input events from mouse not always captured
Shadowphile Post the code.
- Edited
too complicated to post. Input events are polled in the Main node script.
I just put a print statement under the Input.is_action_just_pressed statement and many times it doesn't print anything.
One weird thing thing I've found:
-I'm using the command to call a function in a child node. Normally the _process for the node is just PASSing but the click initiates a sequence of _process calls to implement moving a rectangle around (popup text box).
While that process is running, the input event is captured every single time. It's weird because this seems backwards since there is nothing to cause a lag.
Not using timers, just math with the _process delta value.
edit: just discovered another bit of behavior (I feel a hack coming on lol)
If I move the mouse just a smidgen it recognizes the click every time. Reclicking in the same spot is where I get the weird behavior. I'm not using any move-movement commands. Perhaps I can flush something?
- Edited
Shadowphile too complicated to post
Try to reduce it so it's suitable for posting while still causing the problem. You can't realistically expect someone to debug your code without seeing in.
- Edited
xyz
Ok, I will give it a try. I will have to strip out a ton of stuff (and then the problem will probably go away so in essence troubleshooting myself the really hard way).
Some help works by troubleshooting your code. Other replies use some knowledge based on understanding how Godot works under the hood. The latter is always easier to swallow!
- Edited
Shadowphile There's nothing "under the hood". Querying the Input
singleton gets you the immediate state of input. The problem is much more likely in your code/setup. Especially if - as you said - it's too complicated to post. Trying to untangle it is the way to go so it either becomes postable or you find the cause yourself
Here is the entire project, remember this 3.5.5. I tried importing to 4 but too many problems to fix. I commited to 3 because I kept having crash problems with 4 and my needs are pretty light.
Take it easy on my code. I'm not a 'modern' programmer and laxed into using the global singleton to trigger info back up the scene tree, mostly because since I am swapping nodes in the middle of the tree (by script) I can't get the editor to help me make and install signals.
To observe the problem while running the project: (make sure the Output window is visible as I print debug statements
-hold middle mouse down to swing the view around until the picture on the wall is in view.
-float the mouse over the picture and click (don't hold down). You should see the popup.
-Behaviors to observe:
---Clicking again while the text box is visible will always pop it up again. Seems reliable (click rapidly to observe)
---Clicking again after the box is not visible sometimes works. Keep trying. Once it stops working it tends to repeat the problem. Do not hold the mouse down because my home-made first-click latch will react to the 'is_action_pressed' method.
---IF you move the mouse even one pixel then the click seems to work every time. THIS SEEMS LIKE A CRITICAL OBSERVATION (if only because it might provide an opportunity for a hack)
You can see in the print statements that sometimes you only get a mouse_up state. Both Godot's action_just_pressed and my own latch on the action_pressed either both work or neither works.
thanks for the help!
Shadowphile Can't reproduce it. Looks fine in the code as well. If you query Input.is_action_just_pressed()
every frame, and it seems you do, there's no reason for it not to catch the mousedown event.
Try to run it on a different machine. Maybe your mouse is malfunctioning.
- Edited
I had a different problem in the past with the same godot project. I pulled a working version from git, still a problem. Put it on another computer, with freshly downloaded Godot, STILL A PROBLEM. Then on the original pc I did some editing and accidently got it working again. That tells me that Godot is not independent enough from the code because even though I installed a first-time install of Godot on the other laptop, it still failed.
Since pulling a working version from Git still did not work, then all that is left is something wrong with godot itself, or maybe the registry. (can't remember if I tried reinstalling godot cause that (mostly) would have tested that theory.
Actually, it just occurred to me that it might be traced to a bug in gdscript since it's not a 'real' language, so the bug would have propagated via the project to the other laptop. If it's a problem with GDscript as opposed to some state Godot preserves for itself, then reinstalling Godot won't fix the problem either. That leaves me blindly hacking my way around a bug in the IDE itself, or perhaps reimporting everything, ugh
But yes, thanks for the testing and suggestion. Ignorance on my part would been the easier pill to swallow though lol!
- Edited
Shadowphile You should try to isolate it and make a minimal reproduction project so it can be reported, diagnosed and fixed if it's indeed a bug. Strip things one by one from your project until you're left only with the bug. Also see if there's a way to induce it with 100% consistency.
Btw, Godot is just a standalone executable. It doesn't need to be installed nor it writes anything into registry. So any kind of "re-installation" really makes no difference. You can only try to run the project in different versions and on more machines.
- Edited
I tried stripping out all of the import files and directories and all of the files in the Godot config folder (appdata on Windows) and let Godot reimport but that didn't work.
This could turn into a black-hole of effort and instead a hack is looking nicer and nicer.
Do you know if I can simulate a mousemovement event with GDScript?
Based on this text from the Manual:
Vector2 relative = Vector2( 0, 0 )
.
void set_relative ( Vector2 value )
Vector2 get_relative ( )
The mouse position relative to the previous position (position at the last frame).
Note: Since InputEventMouseMotion is only emitted when the mouse moves, the last event won't have a relative position of Vector2(0, 0) when the user stops moving the mouse
xyz
I seemed to have found the problem since I realized that your test implies that it's a hardware problem.
I tried earlier with a different BT mouse, same problem.
I just tried a wired mouse and can't recreate the problem, sigh.
I can hardly tell other users that they can't use their BT mouse for a game that requires no low-ping performance.
"Even though this would be called a casual game, you still need a wired mouse. Live with it!"
- Edited
Shadowphile So it was mouse after all
Try renaming _process()
to _physics_process()
Also redoing your input system to only use _input()
handler instead of direct polling from Input
object might help.
xyz
Hmmm..good things to look at eventually. I'm going to stick with the wired mouse for now. I think the BT mice go into low-power mode when not moving and don't wake up fast enough to catch the down-click, or something like that. I may be a behavior of these particular mice that won't neccessarily hold with other models. It's an issue for when I eventually export the project but for now this let's me move forward.