In Unreal Engine 5.3, I developed an innovative digging demo using the Blueprint system, which demonstrates how to dynamically dig holes in walls in real-time environments and allows users to customize the size of the holes. This process benefits from the Geometry Script plugin provided by UE5, which implements powerful mesh boolean algorithm capabilities through the Blueprint interface. In this article, I will detail how to perform digging operations dynamically at runtime. Additionally, I will show how to adjust the size of the holes through the Blueprint interface, adding more possibilities for interactive elements in the game world. The methods provided in this article will be beneficial for applications such as architectural simulation, terrain editing, or other scenarios requiring dynamic mesh modification.
Preparation#
Enable the Geometry Script Plugin#
In versions after UE5.0, such as UE5.3, go to the edit bar -- plugins -- and enter Geometry Script in the search bar to enable it and restart UE.
Import the RuntimeGizmo Plugin#
This is a tool that can control object movement, rotation, and scaling at runtime.
It can be purchased from the UE store or found online as free resources. Copy the parent directory of the extracted plugin into the Content folder of the UE project.
Create the Digging Blueprint Class Actor#
Before this, ensure that the Geometry Script plugin is successfully enabled. In the content menu, right-click to create a Blueprint class, search for and select DynamicMeshActor in the middle search bar of the pop-up parent class selection window, and name it BP_DigHole.
Blueprint Node Connection#
Implement the Digging Function#
- Define Variables and Functions
Double-click to open the BP_DigHole Blueprint, click the + sign in the My Blueprint -- Functions panel to add a function named GenerateHole, and add four variables in the variable panel: Dimension (Vector), Size (Vector), DynamicMesh (DynamicMesh), and DragSphere (Actor).
- Improve the Function
Connect the Blueprint nodes as shown in the following image:
Integrate the Gizmo Tool#
- Add an Event Dispatcher in the Gizmo Blueprint
Before this, ensure that the RuntimeGizmo plugin is successfully imported. Double-click to open the BP_Gizmo Blueprint, add an event dispatcher named OnGizmoChanged, and find the Process Interaction function. Connect the following nodes after its execution modifies the axis position:
- Enable Gizmo in the Controller
In any activated Pawn class in the scene (such as BP_CamController), connect the nodes in the Blueprint as shown below:
In this Blueprint, a variable GizmoRef of type BP_Gizmo is defined, using the Event BeginPlay node to bind the BP_Gizmo event dispatcher OnGizmoChanged to trigger the digging function GenerateHole. The latter part displays the mouse cursor in the Game view.
The Left Mouse Button is a mouse left-click event used to trigger the Attach Gizmo function to activate the Gizmo widget in the scene when the left mouse button clicks on the Actor object.
Scene Actor Parameter Settings#
Place a sphere in the scene, named DragSphere. In the content menu, find BP_DigHole and BP_Gizmo, and drag them into the scene. The variables Dimension, Size, and DragSphere of BP_DigHole should be assigned values as follows:
Runtime Effect#
To modify the wall mesh size, you can add a function to modify the Dimension variable. To change the size of the hole, you can modify the Size variable, and to set the depth of the hole, you can achieve this by setting the Z coordinate of the hole under the parent mesh.