I don’t know how to do it with the setup you have there but if you use an object info node and get an object from the scene… The material index in this case appears to reference the position (slot) in which the material resides. So you are referencing the material index of an object (the instance) with two materials, the second is 1. Check out this blend, for 3.1
3_1_material-index.blend (916.2 KB)