# Find nearest point on each object in a collection

I'm trying to find the nearest face on each object in a collection to a reference object, but the Geometry Proximity node is only returning one point - the nearest face in the entire collection.

The image below shows the node setup - I have a Collection Info referring to the collection of objects (3 cubes at varying distance from the reference object the sphere), then a Realize Instance node because Geometry Proximity won't work on instances. Then I have a Points Node to create points from the Geometry Node position output - but it only crates one point, not one for each object in the collection. The rest of the nodes are just for display purposes.

The image below shows the scene setup - a UV sphere as the reference object and three cubes. The red star is placed correctly on the nearest face in the entire collection (the cube in the middle background).

I know I'm probably missing something really simple, but at this point I've gone node blind. Any help will be appreciated.

SIMPLIFICATION: I only want to find the nearest face to the origin of the reference object. That should remove the need to test every face on the reference object with every face on the collection objects.

When you realize your instances they become a single big mesh, and then Geometry Proximity finds the closest point (not points) on that mesh. We will eventually have iterative processes like loops in Geometry Nodes and when that happens we can do this calculation for every individual component as you are imagining now, but as of yet this is not doable, as far as I'm aware.
First it samples the input geometry for a named attribute called "n_index". For the first copy of the node group, this is $$0$$, since that attribute doesn't exist yet. It uses this integer value as an instance index to choose only the first one among the collection children and delete the rest (Delete Geometry). It realizes this chosen instance, finds the closest position on it with Geometry Proximity, and places a point at that position. In the meantime, we add $$1$$ to that n_index value and capture it on our geometry (at that moment, a single point) after joining it with the original point we inherited from our Group Input (at that moment, none).
When we duplicate our custom group next time, it'll sample the n_index and actually find a value—$$1$$, then add $$1$$ to it and capture it with the same name again. This way, with each new copy of the node group we raise the index by $$1$$, delete all instances except the one with this new index, Join a new point at its closest point, and so on and so forth...