


Name the variable Drag Offset.ĭon't worry if you see an error on the On Mouse Button Down node. Right-click the Return Value of the Absolute to Local node, and select Promote to Variable. This stores the location as a variable so we can determine where on the widget the player actually clicked and where it gets dropped. The screen position where the mouse button registered a button down key press. This converts the absolute coordinates of the Health Bar widget to local space by getting From the OnMouseButtonDown node, drag off the My Geometry pin and add the Absolute to Local node.ĭrag off the Mouse Event pin and add the Get Screen Space Position node and connect the Return Value to the Absolute Coordinate pin. Here we will perform some checking when the Mouse Button is pressed and what happens when a widget drag is detected. There are several functions that you can override to call your own custom script. This creates tabs for each of the overrides in the Event Graph.

In the Event Graph, add the OnMouseButtonDown and OnDragDetected overrides. This step enables us to determine if the player is dragging the Left Mouse Button. Then set the Percent to 1.0 so the progress bar is filled and changes color.Ģ.1 - Scripting the On Mouse Button Down Function You can also stylize the Progress Bar yourself by setting the preview to Desired on Screen. In the Details Panel for the Size Box, set the Width and Height Override to 500x50. Open the HealthBar Widget Blueprint, and delete the Canvas Panel in the Hierarchy window.Īdd a Size Box and add a Progress Bar to the box. We also use the DetectDragIfPressed node to determine if the player is dragging with a specified key. In this step, we determine when the Left Mouse Button is pressed and store the location where it was pressed in screen space. With our project setup done, next we will start working on the HealthBar Widget Blueprint which is the piece of UI that we want to be draggable. Check the boxes for Instance Editable and Expose on Spawn.Ĭompile and Save the DragWidget Blueprint. Open the Drag Widget Blueprint, and create a User Widget variable called WidgetReference. This offsets the location from where we start dragging and dropping the widget.Ĭompile and Save the WidgetDrag Blueprint. Check the boxes for Instance Editable and Expose on Spawn. This will be used to hold the UMG Widget that we want to drag around on screen.Ĭreate a Vector 2D variable called DragOffset. Open the WidgetDrag Blueprint, and create a User Widget variable called WidgetReference. This specialized Blueprint Class enables us to pass through information as part of our drag and drop action. Right-click in the Content Browser, create a new Blueprint Class for the DragDropOperation class, and call it WidgetDrag. In the Content Browser, create three Widget Blueprints called: DragWidget, HealthBar, and HUD. For this how-to guide, we are using the Blueprint Third Person template project.
