can I save the material on each individual object? I don't know if there can be a solution here.
GeoNode before applying realize instances

can I save the material on each individual object? I don't know if there can be a solution here.
GeoNode before applying realize instances

I've told you that it will not work if instances are realized. After realizing, whose instances are converted from many objects inside the main object into one object which has one common object position.
The only way to make it work in 3.0 is to calculate distance inside GN and then pass this value using transfer attribute:
But this setup also have some limitations. Since you get an instance index by dividing the point index by the count of points in one instance, you should have instances with the same number of points.
The is also a "Scale-to-Zero" hack to make it works with instances with the different number of points: https://blender.stackexchange.com/a/250698/32374
Or simply try Blender 3.1, where you can make it much easier: https://blender.stackexchange.com/a/250694/32374
sorry, i am always working with 3.1...so here the update for 3.0:
you can use this node setup to get what you want:
with constant in colorramp it looks more like yours: