Controller bindings affect both gameplay and menus for a single frame

SonoSooS

Terrarian
Steam or GOG
GOG
Single Player/Multiplayer
Both
Operating System
Windows 10
Terraria Version
1.4.1.2
Controls Used
Controller (please specify type)
It seems like when opening an interaction menu (opening chests, NPC interaction, etc.), the menu keybindings get applied, but without disabling game interaction for a single frame. This causes an unintended side effect of doing unintentional interactions with the world.

For example, having tool use key on L2 (not important as long as it doesn't collide with menu keybindings), menu confirmation key on A, and interact button also on A (important), when I press A to interact with the NPC, the default action for the currently held inventory slot will be executed (so if I'm holding a block with smart cursor, the block will be placed, or if I'm holding a sword, it'll be swung).

This bug however doesn't seem to affect the world when exiting a menu (can't get the sword to swing for example), other than jump. I guess that's because jumping is not a key press thing, but a key holding thing.


While testing if this bug exists with the keyboard too, I noticed that I can break torches while in a menu if I bind interact to E and menu item select also to E. I don't know if this is an intended power for PC users, or if it's also an oversight.


Edit: controller is an original DualShock 2 (SCPH-10010 A) in Xbox360 emulation mode.
 
I wonder if it could be related to the long-standing bug where if you use a controller to talk to the Guide about Crafting ingredients, it makes you craft an item (if you happen to have the right materials/station/previous placement on the item column-menu) against your will. Like for a split-second it treats the Guide's menu like a normal inventory/crafting menu, just long enough for suddenly having a torch or campfire or crafting table. Maybe it's just easier to hold the button on a controller than on the mouse, so that could be why it happens specifically for the controller? (In my case, an XBox 360 controller.)

And maybe that's why the Interact button being used on a Pylon (on controller) often makes the map screen rapidly flash on and off, with only a 50/50 chance of stopping on the desired state of either opening or closing the map? Because the same button is used to both open and close the menu (toggling), and overlap of the on vs off state due to a frame delay may cause it to rapidly switch between both states?

Some of these are mentioned here (as well as other threads that brought it up over time)... **REPORTED** - Guide auto crafts when choosing crafting from menu, with a controller, on PC

This comment can be ignored if the cases are unrelated, but just thought I'd bring it up in case it might be.
 
I wonder if it could be related to the long-standing bug where if you use a controller to talk to the Guide about Crafting ingredients, it makes you craft an item (if you happen to have the right materials/station/previous placement on the item column-menu) against your will. Like for a split-second it treats the Guide's menu like a normal inventory/crafting menu, just long enough for suddenly having a torch or campfire or crafting table. Maybe it's just easier to hold the button on a controller than on the mouse, so that could be why it happens specifically for the controller? (In my case, an XBox 360 controller.)

And maybe that's why the Interact button being used on a Pylon (on controller) often makes the map screen rapidly flash on and off, with only a 50/50 chance of stopping on the desired state of either opening or closing the map? Because the same button is used to both open and close the menu (toggling), and overlap of the on vs off state due to a frame delay may cause it to rapidly switch between both states?

Some of these are mentioned here (as well as other threads that brought it up over time)... **REPORTED** - Guide auto crafts when choosing crafting from menu, with a controller, on PC

This comment can be ignored if the cases are unrelated, but just thought I'd bring it up in case it might be.

I just did some further tests, and I can also not only 100% reproduce the issue, but also confirms that I basically described this bug bang-on.

If I do a single-frame tap of the interact button (button down on first frame, button up on second frame), this bug doesn't happen at all! No swing of the sword, and no autocrafting! But if I do a two-frame tap (so button down, button held, button up), then the sword autoswings, and the automatically highlighted crafting item is attempted to be crafted.
 
While testing this bug some more, I have noticed that the selected item name flickers, and then almost immediately after I noticed that the controller keybinding help text also flickers!

After doing a frame-by-frame capture, I noticed that it's not a single frame bug, but it happens in multiple frames!

Here's a breakdown:
I press the Interact button (A) to interact with the NPC. I pressed it down in a way, so the game didn't register it in this frame yet.
2021-03-03_21-58-21.png
The game has registered my A press. Notice how it shows the same button help as the inventory, so the game seems to attempt to open the inventory?!
I think it's actually opening my inventory, because if I interact with the NPC while using my sword, the sword magically disappears from the hotbar during the animation, probably because it actually opens a ghost inventory screen, and since A is the key for both picking up inventory items (menu binding), and also the interact key (gameplay binding), they are in effect at the same time.
Mentioning it here, that once the animation ends, the ghost inventory screen closes, and the sword is put back into its proper slot.

Another weird quirk is that this is the only frame where the NPC name hover text has slided to the right a bit.
2021-03-03_21-58-46.png
I can't even explain what is going on with the help text. X is my inventory key (rebinding the gameplay binding of it does make it change in the help text), but how is A both cancel and talk?! :dryadwhat:
Also, "Items".
2021-03-03_21-59-03.png
The help text finally shows what it's supposed to be showing, but the menu is still not usable yet (as can be seen by the lack of selection).
2021-03-03_21-59-34.png

2021-03-03_21-59-52.png
The menu is usable, but the selected hotbar item is used (as if I pressed L2, which is my gameplay interact binding).
2021-03-03_22-00-11.png

2021-03-03_22-00-26.png

Overall, this issue seems to come from two sources (just speculation based on my research I did so far):
1) the game gets really confused between UI and gameplay bindings
2) assuming the game uses KeyDown, KeyHeld, and KeyUp mechanism in any way (Down for just pressed, Held for buttons just pressed or held in the previous frame, and Up is for buttons Held in the previous frame, but not held anymore), it seems like there is no separate Down/Held/Up for UI and for gameplay, and/or there is no filtering when transitioning between gameplay and UI keybindings, which causes these Down/Held/Up values (especially KeyDown in this case) to leak into the new UI, causing these various unintended side effects

If my 2nd assumption is true, then I suggest force updating the Key state, so KeyDown doesn't contain the interact key anymore, so the player would have to release the interact key and press it again if they really wanted to interact with their inventory.
 
Even more testing!

I found out that moving the mouse before interacting with the NPC allows me to continue using the currently highlighted item until I press any button which would cause the currently selected menu item to be changed (like pressing a DPAD button, although weirdly enough L2/R2 can be also used to force update the menu item selection).

I don't know 100% sure, but it seems like there is a ghost inventory screen which the game doesn't even seem to register properly, which causes the currently held item to be used.

The other thing I noticed is that this bug happens because we're in an UI with nothing visually selected. The weird thing is that the game actually correctly registers that a UI is up, and it's in use, and the default menu option is actually correctly highlighted in the menu state, although invisible. However it seems like there is something else going on, because the currently selected item is not reflected on the UI itself (it's not highlighted with orange, and the text is not magnified), and it seems like that's the cause of this bug occurring.

I'll continue my testing further, but I'm still completely lost as to what exactly causes this, despite seemingly getting closer and closer to figuring out what causes this.
 
i sincerely hope you figure out EXACTLY whats going on, because im getting tired of having to Anticipate the auto craft and would rather forget it ever existed.
 
I'm closer than ever!

The main culprit is undoubtebly the mouse cursor. Yes!
It's not visible to the player, but secretly when you use your joystick (or your keyboard arrow keys even), the game just puts the cursor in the middle of the next UI element in the direction you pressed. The game has quite a complex UI navigation system (most likely) just for this purpose.

However, it's not that simple. Actually multiple things work together (or rather, against eachother) to make this annoying bug possible.


1) The mouse cursor is not positioned in time
This is the main culprit for most anomalies. While making the hidden cursor visible again, it's clear as rainbow that it's not positioned in time.
Here's how talking to an NPC goes:
- press Interact key, which the game registers as MouseRight (and QuickMount, but it's probably not important)
- NPC interaction has been registered
- the NPC dialog UI shows, keybindings are already changed from Gamepad to GamepadUI, which means that my MouseRight turned into a MouseLeft
- because the mouse cursor is positioned too slow, and MouseLeft is held, and the mouse cursor is on the player (gamepad autocursor in circle mode), the currently held item is used. In my case, the sword was swung
- a few frames later the cursor jumps to the default option, as it should have earlier (quite literally)

2) Gamepad input layout change doesn't filter out already pressed keys (not intentionally intentional?)
This seems to be the culprit for the guide autocrafting when combined with issue #1.
Interaction flow:
- pressing UI interact key (which game registers as MouseLeft) opens the crafting window
- for some reason some unknown (to me) UI slot is selected, which I can't see where it is when it's selected for those 1-2 frames it is selected
- for a single frame, the item to be crafted is highlighted automatically, but the cursor is not on it yet. MouseLeft is still held
- a frame later, the cursor jumps to the automatically highlighted crafting item button, and it is crafted, in a single frame. In my case, in the previous frame the cursor was still away from the crafting button, but on this frame it had jumped into the middle of the crafting button, and already had 3 torches held in the cursor.

I didn't try the map instantly closing itself issue, as this only time I was unable to reproduce it, while almost always it was way too easy to trigger it after a few tries:dryadgrin:

This all also explains why a single-frame tap doesn't trigger this bug. Because MouseLeft is never pressed, the bug can't trigger!

I really hope a developer sees this eventually, as I'm way too unfamiliar with the PC version code to be able to make a patch for myself, and patching the gamepad layout change filter using my method would take days of manually inputting bytecode. And I also can't even trace down where the mouse cursor positioning trigger points are for each particular issue, let alone finding a more global culprit.

Edit:
An alternative fix for issue #2 would be to make UI code check for MouseDown at the time of opening, and ignore it until it is finally released.
Edit 2:
Sadly the alternative fix doesn't seem to work. Too bad. Not only did the devs already try what I just described, but it seems to do absolutely nothing to help the case of this bug %:sigh:
 
Last edited:
(in darth vaders voice) NOOOOOOOOOOOOOOOOO!!!
thats extremely unfortunate. guess i'll stick with preemptively selecting wood to be crafted every time i want to see the guide for something. :( thanks for your help SonoSooS with helping out the devs getting closer to fixing the god forsaken bug that is the "frame by frame controls free for all".

also, i would like to report this, if you havent been getting this bug on on your side. it may interest you and could be highly likely related to the bug we're currently dealing with.
if you go to a chest and and interact with it (open it), if the first item is equipable (armor or accessory), it will be automatically be switched into your first accessory slot. the same button is used for interacting and making that switch. hence why i may have called it, in my own post about this issue, the double press bug. i hope this info helps with the investigation.:)


ps. i also had the world map flashing on and off at me in 1.3.5.7, but i believe i fix that by changing my bindings, went as far as use a keyboard & mouse to gamepad program just so i can have more keybinding options. i could attempt to reproduce this if you want me to.
 
(in darth vaders voice) NOOOOOOOOOOOOOOOOO!!!
thats extremely unfortunate. guess i'll stick with preemptively selecting wood to be crafted every time i want to see the guide for something. :( thanks for your help SonoSooS with helping out the devs getting closer to fixing the god forsaken bug that is the "frame by frame controls free for all".

also, i would like to report this, if you havent been getting this bug on on your side. it may interest you and could be highly likely related to the bug we're currently dealing with.
if you go to a chest and and interact with it (open it), if the first item is equipable (armor or accessory), it will be automatically be switched into your first accessory slot. the same button is used for interacting and making that switch. hence why i may have called it, in my own post about this issue, the double press bug. i hope this info helps with the investigation.:)


ps. i also had the world map flashing on and off at me in 1.3.5.7, but i believe i fix that by changing my bindings, went as far as use a keyboard & mouse to gamepad program just so i can have more keybinding options. i could attempt to reproduce this if you want me to.
You set the font a bit too small for me to read, but managed to read it.

The reason the double press bug happens is already explained in my 2nd point. You press a keybind which opens your inventory, then the keybindings change from Gamepad to GamepadUI, but you're still holding the keys on your joystick, so it triggers the keybinding under the same physical key with a completely different binding. So for example setting inventory in Gamepad, and menu back button (I forgot the name of the keybinding) in GamepadUI to the same button, you're most likely guaranteed to be unable to open the inventory for this reason, because in Gamepad mode it would act as Inventory button, but when it switches to GamepadUI, you're still holding the same button, but the game sees it as if you released the Inventory button, and pressed the menu back button, even though you never released the button you held to open your inventory. I hope you can understand what I'm trying to say.

Edit: I can't test now, but I didn't test having inventory and menu back on the same button, but I'd be VERY surprised if it DIDN'T trigger the bug.
 
i believe i understand better.:confused: as for the "back" keybind, i think you may have meant "close" which is tied to inventory binding in the ui aka
This.png
IF you meant that, then i have EXTREMELY surprising news for ya. i've had my inventory binding for both gameplay AND menu as the start button for over a year (i think) and has function as intended. it doesnt disallow me to use the inventory at all.

btw, there is a "back" and "cancel". if you go into the the controls or achievements menu, you'll see that back is the inventory button and cancel only appears after you have used the UI buttons called action, build, quick, attack which are all tied to the UI quick mount keybinding. there you'll see cancel using BOTH the interact and inventory keybinding. what i do find odd about this is that you access the inventory while utilizing normal gamepad/gameplay bindings and not gamepadUI/menu bindings.

also, to answer your old question of whether or not if it was intended you could destroy a torch while in the menu: yes, yes you can and much more.




final thing: i've found something but may be unrelated to what we're dealing with. i can make my character use the "use item" binding without holding it.
how to reproduce:
1. have autopause set to on
2. select anything to have selected in your hot bar
3. go to inventory menu
4. use the quick mount binding
5. exit menu

how to get out of it:
1. use the item on something
2. cycle though to something usable, then back to 1


i only added this because i thought it was neat.:D
 
Back
Top Bottom