How can I use GeometryScript blueprint functions in C++ code?

I am trying to use UDynamicMeshComponent to create a procedural landscape, and the collisions are not working at all. I would like to use the Compute Mesh Convex Decomposition blueprint function in C++ so that I can use the convex decomposition as simple colliders for the landscape.

There are a number of other GeometryScript functions that I would like to use as well, such as Recalculate Normals. Is there a way to do this? It seems like C++ isn’t supported much in this context.

1 Like

Hey, I guess you may already have solved your issue already, but you can find them by searching the engine code using your IDE - which is a super handy and generally applicable (I think?) way to find c++ equivalents in UE. So for instance, since there is a BP function called “Append Box” I searched for “AppendBox” which led me to MeshPrimitiveFunctions.cpp.

This particular function you can then call like this:

void ADiggableGeometry::OnConstruction(const FTransform& Transform)
{
	UDynamicMesh* DM = DynamicMeshComponent->GetDynamicMesh();
	DM->Reset();

	FTransform T;
	FGeometryScriptPrimitiveOptions Options;
	UGeometryScriptLibrary_MeshPrimitiveFunctions::AppendBox(DM, Options, T, 100, 200, 400);
	
	Super::OnConstruction(Transform);
}

Placing this in a ADynamicMeshActor subclass will create a simple rectangle when you drag it into the editor window. There are lots of functions available in c++, just type UGeometryScriptLibrary_ and you should see a huge list in your IDE :slight_smile:

1 Like

Im struggling to find a way to get DynamicMeshComponent into my C++ class.
What kind of includes do I need? Thanks

include “Components/DynamicMeshComponent.h”
include “DynamicMesh/DynamicMesh3.h”
include “GeometryScript/MeshBooleanFunctions.h”
include “GeometryScript/MeshPrimitiveFunctions.h”
include “GeometryScript/MeshSpatialFunctions.h”
include “GeometryScript/MeshAssetFunctions.h”
include “GeometryScript/MeshNormalsFunctions.h”
include “GeometryScript/MeshTransformFunctions.h”

and in build.cs :

            "GeometryCore",
            "DynamicMesh",
            "GeometryCore",
            "GeometryScriptingCore",
            "GeometryFramework",
            "DynamicMesh"
2 Likes

Could you please share the full cpp code with headers. Am new to coding and trying to do something similar , i.e. ApplyDisplaceFromTextureMap with no success yet!

Sorry for the delayed response. Maybe someone else are looking for these. Here is how I managed to get them working:

All functions:

D:\Games\UE_5.4\Engine\Plugins\Runtime\GeometryScripting\Source\GeometryScriptingCore\Public\GeometryScript

Includes look like this:

#include "SplineArchitectWall.h"
#include "Engine/World.h"
#include "DrawDebugHelpers.h"
#include "Components/SplineComponent.h"
#include "CoreMinimal.h"
#include "Components/SplineMeshComponent.h"
#include "Components/DynamicMeshComponent.h"
#include "DynamicMesh/DynamicMesh3.h"
#include "GeometryScript/MeshBooleanFunctions.h"
#include "GeometryScript/MeshPrimitiveFunctions.h"
#include "GeometryScript/MeshSpatialFunctions.h"
#include "GeometryScript/MeshAssetFunctions.h"
#include "GeometryScript/MeshNormalsFunctions.h"
#include "GeometryScript/MeshTransformFunctions.h"
#include "GeometryScript/MeshDecompositionFunctions.h"
#include "GeometryScript/SceneUtilityFunctions.h"
#include "GeometryScript/MeshModelingFunctions.h"
#include "GeometryScript/MeshUVFunctions.h"
#include "GeometryScript/MeshBasicEditFunctions.h"
#include "GeometryScript/MeshRemeshFunctions.h"
#include "GeometryScript/MeshMaterialFunctions.h"
#include "GeometryScript/MeshSelectionFunctions.h"
#include "GeometryScript/MeshDeformFunctions.h"
#include "GeometryScript/MeshSelectionQueryFunctions.h"
#include "GeometryScript/MeshSimplifyFunctions.h"
#include "GeometryScript/ListUtilityFunctions.h"
#include "GeometryScript/CollisionFunctions.h"
#include "GeometryScript/MeshQueryFunctions.h"
#include "StaticMeshResources.h"
#include "AssetRegistry/AssetRegistryModule.h"
#include "Components/InstancedStaticMeshComponent.h"
#include "UObject/SavePackage.h"
#include "PhysicsEngine/BodySetup.h"
#include "SplineArchitectCustomPiece.h"

And functions looks like this:

	UDynamicMesh* SkewedMesh = SkewedMeshComp->GetDynamicMesh();

	// Copy Mesh from Static Mesh
	FGeometryScriptCopyMeshFromComponentOptions Options;
	EGeometryScriptOutcomePins Outcome;
	// FTransform LocalToWorld
	FTransform LocalToWorld;
	UGeometryScriptLibrary_SceneUtilityFunctions::CopyMeshFromComponent(
		StaticMeshComponent,
		SkewedMesh,
		Options,
		false,
		LocalToWorld,
		Outcome
	);

	// Get all vertex positions
	FGeometryScriptVectorList PositionList;
	TArray<FVector> VertexPositions;
	bool bHasGaps;
	UGeometryScriptLibrary_MeshQueryFunctions::GetAllVertexPositions(
		SkewedMesh,
		PositionList,
		false,  // bSkipGaps
		bHasGaps
	);