banner
YZ

周周的Wiki

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

UE5 Blueprint Practical: Dynamic Wall Digging and Custom Pit Sizes

In Unreal Engine 5.3, I developed an innovative digging demo using the Blueprint system. This demo showcases how to dynamically dig holes in walls within a real-time environment, allowing 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 demonstrate 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 any other scenarios that require 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 allows for the control of 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 your UE project.

Create a Digging Blueprint Class Actor#

Before this, ensure that the Geometry Script plugin is successfully enabled. Right-click in the content menu 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 image below:
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 (e.g., 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, and the Event BeginPlay node is used to bind the OnGizmoChanged event dispatcher of BP_Gizmo 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 an Actor object.

Scene Actor Parameter Settings#

Place a sphere in the scene, naming it 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, a function can be added to modify the Dimension variable. To change the size of the hole, the Size variable can be modified, and the depth of the hole can be set by adjusting 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.