How to batch merge material slots in CAD assets?

Hi,

I’ve got models imported from CAD (Step files from Solid Works) through Datasmith, and need to merge them to reduce my number of drawcalls (which goes well about 20k) since it’s meant for VR.

The current issue I’m getting is that the merge actor (https://i.imgur.com/g6T5Iej.png) doesn’t take into account duplicate material instances, and therefore just stacks material slots. I end up with assets of more than 5000 material slots, and no way to easily reduce that number. All i’m looking for is a way to merge every material slot that points to the same material for now.

Due to the amount of meshes I’m working with, exporting to Blender and reimporting to UE4 isn’t really an option, as Blender 2.80 absolutely stops as soon as I try to do anything with materials when a mesh has more than a few hundreds (regardless of the hardware used). I couldn’t find a way to do it in batch in the editor, with editor scripting or with the Python API. Anyone has an idea on how to remedy that?

Thanks,
Cafe