Download

Get Widget under Position

Hello, I would like ask if there is some kind of 1D Trace or hit check in UMG. I have position X Y and I need to get reference to widget which is at that position. Something similar to hit check which is performed on mouse click, It just needs to have vector2d parameter for coords.

Thank you :slight_smile:

Not without laying out the UI, which is an expensive operation we only do once a frame.

Why?

I really appreciate your activity and help Nick, thank you :slight_smile:
I am working on tetris style inventory and when I am have some item selected and attached to mouse I want to place it back to inventory easily, just one hit check from cursor is not enough because I would like to have a bit of tolerancy and nice snapping even when item is not correctly in place. For example, cursor can be off inventory, but left part of item icon can be inside inventory, I would like to do line check at top left and bottom right position of selected item to determine if there is inventory slot behind it.

I tried this (it outputs size x for test, not widget) and I think it works, what do you think, is it safe ?

EDIT: I test it in on mouse move event and it crashes game on exit, maybe some safe check is needed.

Hi there,

why not implementing the DragOver event inside your inventory slot, so this one fires when you move over the widget during a drag operation.

I know this goes against:

but as a normal player i would assume to drop my item out of inventory when im outside the inventory with my cursor. So your intention feels a bit strange to me, and
i dont think there is a game where it happens that the dragged image location is more prioritized than the cursor location.

cheers

I wouldn’t try and make this with multiple widgets. If I wanted to make a diablo/tetris style inventory I would make a single Slate widget that knows how to layout tetris children slots, and knows how to handle the drag/drop requests, rather that a ton of individual widgets that attempt to share responsibility. Personally - if the cursor is off the inventory, I wouldn’t expect it to try and snap still.

It’s probably crashing because the Slate Application has been cleaned up, you’ll probably need to check if FSlateApplication::IsInitialized() i think is the call. There may also not be a top level interactive window, and you’re assuming there is always a widget found, which may not be true. You must first check if there are any widgets before getting the last one.

Thank you guys, I found different way.

I don’t want to hold button during drag. I just do one click on item to select it and then second click on inventory slot.

When you have item selected you don’t see cursor. So for example, cursor can be near right edge of item icon because of offset… In that situation 90% of item (left side) can be inside inventory but right edge, where invisible cursor is can be outside of inventory, that’s why you can’t place item to inventory even when most of item is already on top of inventory widget.

Thank you for suggestion, I have already implemented second system. I think it is simple but not that fast, your solution would be better. I have invisible button for every slot and when I place there item, item icon is rendered from top left widget and covers other slots too. It is invisible for hit check so when I click again on the item, invisible slot registers click and removes assigned item. Inventory component is implemented in C++, so in UMG i just call simple functions like add item, remove item, get item (row, column)…

Maybe it sounds a bit complicated but it is not.
I did a bit of math and now everything is perfect, so thank you for advices guys!

Anyways, I belive that kind of trace 1d can be handy in some other situations too, maybe it can be added as feature request to consider.

Yeah, then that system does make sense if the cursor is not shown, but the item representative is. Ok.

I am back with very similar question: Is there some out of box way to detect if mouse is on the widget ? I need this to be able ignore game actions when my mouse is on HUD but I don’t want to do Set Input Mode UI Only because I still need to capture input. I belive my function above will be great for this but I am not sure if it is proper way.

https://answers.unrealengine.com/questions/294890/trouble-with-input-focus-ui-vs-game.html