Detecting Key Press During Drag And Drop Operation

I have been following an inventory tutorial from UE4 that is about 5-6 years old. Amazingly enough, the code works well other than a few issues most of which I have solved.

My question, is there any way to hold a key down (in this case “Left Shift”) while dragging an item? The tutorial basically has an inventory slot, that when dragged and holding Left Shift will split a stack in half. I can share some code if someone is willing to help if needed.

Greatly appreciate any help here.

Hey @RedlotusGames! Welcome to the Forums!

A few questions to get things started:

  • What engine version are you using?
  • Is this behavior while holding or on initial click?
  • Would you mind sharing the blueprints you have so far?

Any additional information you provide may go a long way in solving your problem!

1 Like

Hey @Quetzalcodename appreciate the quick reply and the welcome!

I’m using UE 5.2.1 currently. I’ll post some info below:

I’m following this tutorial: https://youtu.be/NcjWb2CMzPo?si=TtSyO4npwwUJd6eg

The behavior is basically left clicking and holding the mouse while also holding down the left shift key on an item in a slot-based inventory then dragging the item to another slot on-drop it should split the stack based on a divide by 2 in the code and place half in the new slot and keep the other half in the original slot. Without left shift held it will just move the items to the new slot (moving to new slot works).

Here is the Key Press in my 3rd Person Character

image

My “On Drag Detected” that looks for the bool “Is Shift Down?”

The On Drop here is where I am pretty sure it fails mostly on the call to the bool “Was Shift Down?” and the Split Stack to Index. (2nd image)

I can share more if needed such as the Split Item to Index function or the On Drag Over if needed. Appreciate the assistance. I also apologize for the messy blueprints and lack of comments, this is my first real foray into UE.

Quick Update: After adding a breakpoint in the “On Drag Detected” on the Branch just after the "Was Shift Down? bool, it is not detecting the Shift Key as being pressed. I am thinking it may be because I’m using a third person character… not 100% sure. Hope that is enough information to help.

Update I found the issue. It was caused by having the “Input UI Only” set. If I set it to “Game and UI Only” it works. I want to use “UI Only” to prevent the Character movement when the inventory is open. Is there any other way to disable character movement when a UI is active?

After playing around more and more I solved most of my issues. I was using “UI Mode Only” due to prevent some things:

  1. Preventing camera movement (this is now fixed with the set ignore look input).
  2. Preventing the player camera zoom via mouse (this is still an issue due to “Input Game and UI”.
  3. When clicking on the viewport with the inventory widget in focus, causes the “I” (used to open and close inventory) to have to be pressed twice or the inventory widget to be clicked in order to close.

So, I updated to this:

Issues 2 and 3 are still now solved. However, I can use “Input UI Only” to solve them, but then this disables the Shift Key issue from the original post.

1 Like

Hey @RedlotusGames!

Is there a specific reason setting your shift functionality in your character instead detecting it in your widget? For example, there is an “is shift down” blueprint node that you can use:

image

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.