Populating material slots for procedurally generated instances

Hi,

I was looking at Christopher 3D tutorial (https://youtu.be/oJUuQJUg9MA?si=VQiYaokEWwKsOBvW ) for setting a material ID randomly for each instance generated with distributed instances on points starting from an object existing in the blender 3d space. If the instanced object has 5 materials for example, the instances inherit them and you can set material id with a random value between 0 and 4.

Then, I wanted to apply this random material assignment with procedurally generated instances but there was an issue: those instances did not inherit material slots from anyone. A bit of research on google and I’ve seen a user (Robin Betts on https://blender.stackexchange.com/a/263553/248575 ) suggesting to use geometry union between an object that has materials’ slots populated (in my case the same plane which I’ve used as input for distribute points on faces) and the procedurally generated instance. Before the union you assign a specific Id for the object with materials in order to be able to delete it before giving the instance as input to distribute instance on points.

I’ll attach the geometry node graph, the first group above is necessary only with the procedurally generated instance, if you use an object as instance you can simply add materials to it and then feed it directly into instance slot of distribute instance on points.

Is there a better way to populate material slots for procedurally generated meshes?