Method to mass-import thousands of materials?

Yes, this is 100% possible to do (I’ve done it before in-game with a custom blueprint obj importer). Since your materials are setup for another engine, you will need to write a custom importer to import them. Luckily, you can do this all in blueprints.

Since your meshes are already obj, you should be able to import those normally with the editor (but you can still use blueprint, too). Your real problem is just the materials and textures.

Engine Version:
The engine version I’m using is 4.20, so things may be different for you.

Plugin:
The only plugin you will need is Rama’s Victory Plugin. It will be used to load in the text files.

Making the Blueprint:
You can either do this with a blutility, or you can make a blueprint class and place it in a level (which is what I am doing).

Create a new blueprint class, and make it’s parent class “PlacedEditorUtilityBase” (this may be different on your version). This is important because it will give the blueprint access to editor utility functions.

If this doesn’t work, you can use the docs to figure out what type of asset to create. Whatever it is, it needs to support editor utility functions.
If you can’t find what to use, you can just install 4.20, import them there, and then migrate the assets to a newer project.

Making Buttons:
To make a button in the details panel, make a function and check “CallInEditor”. This creates a button that lets you run the blueprint in-editor without pressing play. If it has any input parameters, it won’t show up, so to make input variables, just use regular class variables and make them editable.

Importing the Material Files:
Using the Victory plugin, you can use the node “LoadStringArrayFromFile” to load in a text file as an array of strings, one for each line. You can them parse them to get the parameters.

Alternatively, you can convert the material files to csv or json and import them as data tables. This would remove the need to parse them, as well as the need to install the plugin. There are also json plugins available which can import json directly into blueprints, but I haven’t used those.

Importing the Textures:
To import a texture, read its path from the material file. Then, use “ImportAssetsAutomated” to import them directly as assets in your project. You need to supply it with import data, which you create by using the “ConstructObject” node and setting its variables. The only necessary variables to set are “DestinationPath” and “Filenames”. The other variables are optional. The important thing about this node are that it imports files directly as assets rather than just storing them in variables. It also supports every filetype that works with the engine, so you can use this to import other types of assets, too.

The returned value is an array of all successfully imported assets. However, it is **IMPORTANT **to connect it directly to a set (variable) node before doing anything with it. When I connected it to a foreach loop and imported 1 asset, it imported it 3 times. Connecting it to a set node solved this.

Creating the Materials:
Since the materials all have common parameters (ex. diffuse map, normal map, emissionColor, specularPower, etc.) you can setup a base material that has all of those parameters already defined and connected. Then create a material instance of it (right click -> create material instance) and leave it as is. In the blueprint, for each material file, duplicate the base material instance using “DuplicateAsset” and set the parameters using “SetMaterialInstance(X)ParameterValue” (scalar, vector, or texture). This way, you don’t need to worry about setting up a new node graph for each of your materials and deal with the shader compile times.

Alternatively, there are functions where you can actually construct an entire new material graph (create, edit, delete, and connect nodes) solely in blueprint. But this a little more involved and would require shader recompilation for each new material.

Importing the Meshes:
You can either import the meshes using the editor, or you can import them using the same method as the textures. Either will work. I would recommend importing the meshes first, one at a time, importing the materials after each mesh. That way, you don’t have to search for the materials later to assign them as they will be already stored in your intermediate variables. However, if you import materials first, then import meshes, there are nodes you can use to search for the material assets.

Assigning the Materials to the Meshes:
If you decide to import all the materials first and import the meshes using the editor, the editor may be able to automatically find and assign the materials. If not, you can assign the materials through blueprint.

To assign a material to a mesh asset, use the “SetMaterialEditorOnly” node. This node sets the material of the mesh asset itself rather than a mesh in the level.

End:
Save your project and that should be everything.

The attachments contain three examples, none of which use any plugins:
-new material instance: shows how to make new material instance assets through blueprints.
-import files: shows how to import assets through blueprints; these can be any filetype unreal supports.
-import textures and create material: combines the first two methods to show how to import textures, create materials, and assign the textures to the materials.

Blutility:
If you want use blutilities instead, you can possibly simplify the process. Import all the meshes into the editor first. Then make a blutility called “GetMaterialsForMesh” that would do all of the above stuff, but only on the selected mesh.