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.

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