How to Click, Drag & Drop ingame 2D Objects

I’ve tried to find the answers myself but whatever I found I always found myself in a dead end. Outdated tutorials, works only with widgets etc. The most promising seemed to be the “get hit result under cursor” but it doesn’t seem to work with 2D Objects. Some pointers would be much appreciated.

Have you seen this tutorial? HTF do I? Drag and Drop: The Basics ( UE4 ) - YouTube

Basically you have to use the OnDrag and OnDrop events, that you can override in your Widget’s functions section.

Yes I have but since I’m too new I can’t use that tutorial for ingame (non widget) objects.
I’ve tried that method with my 2D Objects but I do not have any OnDrag, OnDrop options under override there. That only seems to work for widgets.

What do you mean by ingame 2D objects?

An object with flipbook or sprite. I’ve found this tutorial: - YouTube Works fine for 3D Objects but again not with Flipbooks or Sprites

-Oh wait it works for sprites but not for flipbooks. Really strange same object with sprite works but not with flipbook. Collision is exactly the same. (I’m doing the the mouse over test) Flipbook Collisions weren’t enabled. Fixed that hopefully I’ll be able to get the drag & drop with this tut.

-Finished the tutorial but the line tracing doesn’t work nor the pickup and drop. So I’m stuck again.

Maybe the 2D game world objects do not have the right Collision settings for the mouse clicks to “collide” with them. If you do a LineTrace on the same channel as a mouse click uses, and you can get it to detect a hit, then you’re halfway there.

After that, I think there is not a built-in drag capability for in-game objects, so you’ll have to make it yourself by using variables to store what is clicked on and being dragged, and also handling the OnRelease event.

The trickiest part will probably be detecting if the 2D game objects are visually overlapping one another as if they were in a 2D menu, but you can do most of this by deprojecting their corners or bounds from world coordinates to screen coordinates and seeing if the X and Y are between the X and Y of the other.

I haven’t tried this myself but that’s my plan if I were to attempt it.

If you cannot get it to detect the mouse click/release upon the 2D game object at all, then you can use the same technique I mentioned for detecting if they’re overlapping, and just check that whenever there’s a mouse button press down event, see if the cursor’s screen coordinates are within the deprojected object bounds’ screen coordinates to decide whether to set the DraggedObject variable you make for it, or to clear it.

That brings to mind another thing to figure out - when you drag the object, where will it be positioned in world coordinates? somewhere a fixed distance from the player in the direction they’re facing?

It might be easier to hide the 2D object in the world, add it as a Widget for dragging, then project it back onto the 3D world when they drop it.