Boolean union and preserving original materials

Hello, I’m new to blender and I’m trying to recreate this example of boolean-union where two objects with different materials end up as one shape but with two materials. The result should be “now a single mesh object and the faces of the new object have the material properties of the corresponding surface that contributed to the new volume based on the Union operation.”


however when i do it, the union results in a single mesh object with just one of the original materials.

I first add new different materials to each objects and make them different colour by changing the ‘diffuse’ color property. I then do add modifier - boolean - union - apply.

before union:


after:


(I’ve moved the original yellow box out of the way, the booleaned object is all-red).

Any help getting the original colors to stay is much appreciated!

The object with the boolean modifier needs to have both materials in its material list