Is there a way to sample procedural meshes? If I add a PCG component to a BP with a Static Mesh, and then inside the PCG Graph connect the In > Sampler it will know that it should scatter points on to the static mesh. However, if I try the same thing with a Procedural Mesh component in my BP instead of a Static Mesh, it doesn’t work. Do you know a way to sample a procedural mesh?
Hey, I’m also interested in learning how to combine Procedural Content Generation and Procedural Mesh.
This is somewhat helfpful, but the use case here is still different from what me and the OP are asking (presumably). The approach described in this video still needs a landscape that is the initial “Source” of the PCG Graph.
What we need is a node in the PCG Graph that takes a procedural mesh as an input and samples points onto it. I will continue searching and keep updating if I find anything.
If I’m understanding the question correctly, using a World Ray Hit Query node into Surface pin of a Surface Sampler node worked for projecting the points onto a procedural mesh for me.
credit: How can I project points created with PCG onto meshes? - #2 by ClockworkOcean
So I’m in the same boat here. Did y’all have any luck?
I’ve got a procedural mesh component and a PCGComponent, both created at runtime, the latter from a graph provided through a blueprint subclass.
UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
UProceduralMeshComponent* TerrainMesh;
UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
class UPCGComponent* PCGComponent;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
class UPCGGraph* Graph;
Ultimately, I create the mesh and call Generate on the component:
TerrainMesh->CreateMeshSection_LinearColor(0, Vertices, Triangles, TArray<FVector>(), UVs, TArray<FLinearColor>(), TArray<FProcMeshTangent>(),true);
if (TerrainMaterial != nullptr)
{
TerrainMesh->SetMaterial(0, TerrainMaterial);
}
PCGComponent->Generate();
Nothing happens. I’m using the previously discussed Word Ray Hit Query connected to a Surface Sampler:
The same graph generates fine when placed manually in a PCGVolume in the editor, so long as the volume overlaps a surface. I’m not sure what’s wrong here – the cast ray not hitting the mesh, the mesh not being of an appropriate type, not having an explicit volume, etc. (I’m using UE 5.5.1).
Bonus question: Assuming I had added some pins to the “Input” node of the graph so I could provide arguments, how would I populate their values from C++? Or is there another way to “pass” arguments from the C++ actor into the graph? (Most of the options in Blueprints aren’t available in PCG Graphs). Because the other option is for me to somehow get the mesh out of the UProceduralMeshComponent and pass it into the Surface sampler directly.
Got this working, eventually. This is maybe a little more superstition than established fact, but it seems that:
a) There must be a box collider present (even if collision is turned off for it) to act as the “volume” for the PCG node,
b) There must be a PCGWorldActor existing somewhere in the world. (I got mine by adding a PCGVolume to the map and then deleting it – the editor wouldn’t let me delete the PCGWorldActor that it added with the PCGVolume). I suspect this requirement could be met by deriving the C++ class that the blueprint is based on from APCGWorldActor, but didn’t actually try it, and
C) The generator must be set to “Generate at Runtime” – “Generate on Demand” doesn’t work.
I was also never able to get it to hit/not hit surfaces based on a tag, which might be a bug or just me doing something wrong.