Code driven inputs to materials

Hi, global material parameter collections are a way for materials to get input from the outside, C++ code or Blueprints. Is there another way to get code driven inputs into materials?
What I am after is for a material to get an input from the mesh it is applied to, and this input needs to be driven by the code. For example, say meshes A and B use the exact same material (or the same material instance). I want the material to behave differently depending on whether it is applied to A or B (for example a color). I could do this using a different material instance, but for my need this is not possible to use this, I need something that the code can drive and that is relative to the mesh the material is applied to. Is this possible?