Is there a way to export a model with the texture created from part colors?

So, I have gun models, but they contain numerous components, and all I need are some single mesh gun models. As a result, I decided to use export selection on the gun models and import them to solve the problem. The weapons would not import with a texture if I did this. Is there a way to export a model and have the colors of its parts generate a texture?

assuming you use blender,
you can color each component individually via vertex paint
then join each part and export as fbx