Preserve materials when joining meshes In this answer is explained how to create an object which looks like a nucleus.

However, I have a problem when merging multiples spheres into one object. Exactly what I do is the following

1) I created a parent object with many spheres.

2) Then I do Object -> Apply -> Make duplicates real. This will give me all spheres, which are as before colored in red and blue.

3) I select all these spheres and Object-> Join (Ctrl-J). This gives me a single object that I would like to further use as a base object for other geometry.

But after step three all spheres become of the same color. 

The question is how to preserve colors of individual spheres when Joining them into a single object?

Thanks in advance.
(I was using blender 2.80)
Perhaps a more suitable way of generating instances would be with a Particle System?


CtrlG Make a Group of a proton and a neutron
Make an Emitter object, (maybe a rounded cube, to avoid crunching at the poles?)
Assign a Particle System to the emitter
No physics, start and end frames at 1
If you want to vary the proportion of neutrons and protons, you can 'Use Count' in the settings


Settings to taste, but this produced the illustrated result.




Now you can hit 'Convert' in the modifier stack of the emitter.. and..
..Ctrl ShiftA 'Make Duplicates Real'
Because the material is not dependent on Object ID,  Ctrl
J preserves materials