banner
YZ

周周的Wiki

种一棵树最好的时间是十年前,其次是现在。
zhihu
github
csdn

UE5 Blueprint Practical: Digging Pits on Dynamic Walls and Custom Pit Sizes

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.
image.png

Import the RuntimeGizmo Plugin#

This is a tool that can control object movement, rotation, and scaling at runtime.
image.png
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.
image.png

Blueprint Node Connection#

Implement the Digging Function#

  1. 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).
image.png

  1. Improve the Function

Connect the Blueprint nodes as shown in the following image:
image.png
image.png

Integrate the Gizmo Tool#

  1. 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:
image.png

  1. 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:
image.png

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:
image.png

Runtime Effect#

hole

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.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.