How to render lots of small meshes?

If I have an array of positions and colors, is there a way to render those using one (instanced) mesh?

In this case, I have cube mesh and want to render a few thousand per frame, each with different colors. Basically voxels, but dynamic generated and animated dynamically.

Try using mesh particles?

Maybe take a look of UProceduralMeshComponent. We can putt all your position in this component for make a mesh.

Can you manually control the particle position/color/etc from code?

I’ve not tried yet, but I’m sure you can get there by using Niagara system.

I have tried mesh particles and it looks tangible

UParticleSystem and the new Niagara on paper look ideal with mesh particles. BUT I can’t find a way to manually manipulate the particle XYZ and color every frame.

UInstancedStaticMeshComponent is a bit more promising because I can control the XYZ per frame. BUT I can’t find a way to feed per instance material parameters, so each cube has a unique color.

Pseudo code…

struct Cube {
FVector pos;
FColor color;

int numCubes;
Cube cubes[10000];

Then I need some way to update those every frame.

As of 4.25, it is now possible to pass in custom data per-instance. I haven’t used the feature myself yet, but googling “unreal 4.25 per instance custom data” without the quotes brings up video tutorials

a quick glance at the code for instanced static mesh component, it looks like you need to use UInstancedStaticMeshComponent::NumCustomDataFloats, and UInstancedStaticMeshComponent::PerInstanceSMCustomData

Thanks for the lead! I have been banging my head for months on this, will keep poking.

Boom! goes the dynamite instances.

PerInstanceCustomData] (and VertexInterpolator for some reason to make it work) pulls the data from the Instanced Static Mesh Component’s custom data.

I still wonder if there’s a more efficient/powerful way to do this, but for now… this is the way.