I learned this trick sometime ago but I have forgot. So what I want to do is add different material to an object using other object. For example I have two cubes. One has red material and one has blue material. By overlapping those cubes I'd want the material on the overlapping part of the red cube to turn into blue. Sample image below. Actual use would be far more complex case with no matching edges to manually set materials
You can create 2 overlapping cubes. Create somewhere a third cube that will be the boolean object and make it invisible in render. Give your 2 first cubes 2 different colors, give them both a Boolean modifier with the third cube as Object. For the orange cube, choose the Difference option, for the blue one, choose Intersect.