Create Action Utilities With Geometry Scripting

Build a fundamental understanding of using Geometry Scripting through Blueprints by creating action utilities.

When you're creating or editing geometry in a level, you might need to perform repetitive tasks. You can use action utilities to alleviate these types of repetitive tasks. You can also couple action utilities with Geometry Scripting to create efficient mesh editing workflows. You can create right-clicking actions that can help quickly change the style of meshes, recompute UVs, adjust pivot locations, and much more.

This guide shows you how to:

  • Create scripted action utilities to help automate tasks.

  • Setup core Geometry Scripting nodes.

  • Use Geometry Scripting to create a utility for reducing triangle density in a mesh.

Although the guide focuses on simplifying (reducing triangle count) a mesh, you can use the script as a template to create more complex workflows.

Prerequisite Knowledge

To understand and use the content of this page, make sure you:

You can use any project to follow along. To create proxy geometry for testing purposes, use one of the primitive shapes in Modeling Mode. To learn more about this editor mode, see Modeling Mode Overview.

Enable Plugin

Geometry Scripting requires that the associated plugin is enabled.

To enable the plugin or verify that it is already enabled:

  1. In the Menu Bar, click Edit > Plugins.

  2. In the search bar, type "geometry script".

    Enable Geometry Scripting Plugin

  3. Enable Geometry Script plugin, and click Yes in the dialog popup.

  4. Restart the engine.

Create a Utility Class

To get started, you must create a Blueprint class to build your action utility. This guide uses Actor Action Utility to right-click actors in the Level Editor to perform a scripted action. You can also choose the Asset Action Utility to right-click an asset in the Content Browser.

To create the utility class:

  1. In the Content Browser, click Add or right-click, then click Editor Utilities > Editor Utility Blueprint.

  2. Search and click Actor Action Utility.

  3. In the Content Browser, give your new class a descriptive name, such as ActorAU_Simplify.

Create a Function

After creating your utility class, the next step is to create a function. The goal of the script is to simplify a mesh to a given triangle count.

To create a function:

  1. Double-click your new Blueprint to open it in the Blueprint Editor.

  2. In the My Blueprint panel, click the plus icon in the Functions category and name the function Simplify Mesh. Double check Call In Editor is enabled in the Details panel.

  3. In the Details panel, click the plus (+) icon in the Inputs category to add a parameter.

  4. Make the parameter an integer and name it Triangle Count. This input parameter triggers a prompt when the script is activated, letting artists enter a target triangle count for the simplification method.

  5. Promote Triangle Count to a local variable by right-clicking its output pin and clicking Promote to Local Variable.

  6. Name the variable Triangle Count.

Creating a Simplify function

Restrict to a Specific Actor Class

If you compile and save your Blueprint, and then begin right-clicking actors in the level, you may notice the Scripted Actor Actions option appear in the context menu. The script is available for any actor class, which can cause confusion if the script is not designed for multiple classes. To control what actors artists can affect, you can restrict the scripted action to a specific class.

To adjust the supported class:

  1. In the top toolbar, click Class Defaults.

  2. On the Supported Classes bar, click the plus (+) icon.

  3. Search for and click Static Mesh Actor.

    Class Defaults

  4. Compile (Ctrl + Alt) and Save (Ctrl + S).

Core Geometry Scripting Setup

Now that you have established your script with a function & supported class, you can begin implementing geometry scripting nodes.

A core step in setting up your script is to create a dynamic mesh for editing. The dynamic mesh acts as a temporary mesh you can perform your operations on before applying them to your static mesh. This temporary process avoids unnecessary geometry in the editor, helping save on computer processing.

Dynamic Mesh Pool

To create a dynamic mesh, you must request it from a dynamic mesh pool.

To set up a dynamic mesh pool:

  1. Right-click in the event graph and create a Create a Dynamic Mesh Pool node.

  2. Connect the execution pin to the Simplify Mesh function.

  3. Right-click the Dynamic Mesh Pool output pin, then choose Promote to Local Variable.

  4. Name the variable DM_Pool.

  5. Connect the execution pin to the Triangle Count SET node.

  6. Compile (Ctrl + Alt) and Save (Ctrl + S).

Creating a Dynamic Mesh Pool

Get Actor's Asset

Since Geometry Scripting operates on UDynamicMesh, the static mesh asset of the selected actor is needed. In addition, for each chosen actor, you must ensure any shared static mesh assets are operated on only once. Although this function executes based on a target count (avoiding duplicate operations), it will run unnecessary computations if the selected actors use the same static mesh asset.

To get a unique static mesh asset:

  1. Drag off the Triangle Count Set's execution pin and create a Get Selected Actors node.

  2. Drag off the Return Value pin, create a For Each Loop node, and connect the execution pins. These connected nodes iterate through the selected actors.

  3. Drag off the Array Element pin, create a Cast to StaticMeshActor, and connect the execution (Loop Body) pins. Cast to Static Mesh Actor ensures you are using static mesh actors only.

  4. Drag off the As Static Mesh Actor pin and create a Get Static Mesh Component node.

  5. Drag off the component pin and create a Get Static Mesh node.

  6. Drag off the Static Mesh pin and create an Add Unique node. This node appends each unique static mesh to an array.

  7. Connect the Cast to StaticMeshActor's execution pin to Add Unique.

  8. In the My Blueprint panel, click the plus (+) icon in the Local Variables category to create a new variable.

  9. Name the variable SM_Array.

  10. In the Details panel set the variable type to Static Mesh and the container type to Array.

  11. Drag the variable into the graph and click Get SM_Array to make it a getter. Connect the array pin to Add Unique.

Get Selected Actor

With the new list of unique static mesh assets, the for loop is completed.

Create a Dynamic Mesh

To convert to a dynamic mesh:

  1. In the For Each Loop, drag off the Completed execution pin, then create another For Each Loop node.

  2. Drag the SM_Array variable into the graph and make it a getter.

  3. Connect the array output to the For Each Loop node.

  4. Drag the DM_Pool variable into the graph and make it a getter.

  5. Drag off its pin and create a Request Mesh node. This node pulls a dynamic mesh from the Dynamic Mesh Pool node you created earlier.

  6. Connect the For Each Loop's execution pin to Request Mesh.

  7. With the dynamic mesh acquired, you can convert your static mesh. Drag off the Return Value pin, create a Copy Mesh from Static Mesh node, and connect the execution pins.

  8. Connect the Array Element output pin to the From Static Mesh Asset input pin.

Create Dynamic Mesh

Geometry Editing

With the dynamic mesh created, you can perform all your desired procedures and manipulations before applying them to your static mesh. In this script, you only use one node to perform mesh editing.

  1. Drag off the Success execution pin from Copy Mesh from Static Mesh and create a Apply Simplify to TriangleCount node. The simplify node attempts to reduce the triangle count to the given input value.

  2. Connect the Dynamic Mesh output pin to the Target Mesh input pin.

  3. Drag the Triangle Count variable into the graph and make it a getter.

  4. Connect the variable's output pin to the Triangle Count input pin.

  5. Compile (Ctrl + Alt) and Save (Ctrl + S).

Simplify Triangle Count Node

To learn more about the various functions for selecting and editing a mesh, see Geometry Scripting Reference.

Convert to Static Mesh

After finishing the edits, you must convert the dynamic mesh back to a static mesh to apply the modifications appropriately.

To convert back to a static mesh:

  1. Drag off Apply Simplify to Triangle Count's execution pin and add a Copy Mesh to Static Mesh node.

  2. Connect the Target Mesh output pin to the From Dynamic Mesh input pin.

  3. Connect the Array Element output pin from For Each Loop to the To Static Mesh Asset input pin. The changes you applied to the dynamic mesh are transferred to the selected static mesh.

  4. With the edits copied to the static mesh, you can return the temporary mesh to the pool to reuse its memory. Drag the DM_Pool variable into the graph and make it a getter.

  5. Drag off the variable's pin and add a Return Mesh node. When the event is triggered, all compute meshes the pool has allocated will be released.

  6. Connect the Dynamic Mesh output pin to the Mesh input pin.

  7. Connect the Success execution pin.

  8. Compile (Ctrl + Alt) and Save (Ctrl + S).

Converting to Static Mesh

End Results

Copy Node Graph

Simplify Actor Action Utility

With your Blueprint saved and compiled, the Scripted Asset Actions > Simplify Mesh option should appear in the context menu when you right-click a static mesh in the level. Clicking the Simplify script reduces the number of triangles in a mesh until it reaches the target count. This script creates a workflow for applying edits to multiple assets and updating your level quickly.

On Your Own

You can continue to build upon this script or use it as a foundation for another function.

Instead of copying all the nodes in a new function, you can turn the setup and end nodes into macros. Make sure to recreate the local variables properly.

Using what you learned, try making the following adjustments:

  • Apply deformation to the mesh using the Apply Bend Warp to Mesh node.

  • Flip the normals of the mesh using the Flip Normals node.

  • Convert the script to an Asset Action Utility class. Use the Get Selected Assets node instead of Get Selected Actor.

Simplify Asset Action Utility

To continue learning about action utilities, see 33 Scripted Action Utilities on the Epic Developer Community portal.

Help shape the future of Unreal Engine documentation! Tell us how we're doing so we can serve you better.
Take our survey
Cancel