• In 3d

    Automatic material creation in Unreal Engine with Python

    Potential task for automation is creation of material instances for a lot of meshes. For example, I use Houdini to generate a lot of assets procedurally – models with baked texture maps. Importing all these meshes, textures and creating material instances (based on common master material) and assigning respective textures for each model is repetitive and boring manual task. Here is a sample python script that is meant to run on selected static meshes – it will automatically create Material Instance asset for each mesh based on its name and assign all textures also based on name. At the end it assigns newly created material instance to the mesh. It expects textures to be named the same as static meshes, but with appropriate postfixes – “_basecolor”, “_normal” etc. It also expects standard folder structure: import unreal def set_mi_texture(mi_asset, param_name, tex_path): if not unreal.EditorAssetLibrary.does_asset_exist(tex_path): unreal.log_warning(“Can’t find texture: ” + tex_path) return False tex_asset = unreal.EditorAssetLibrary.find_asset_data( tex_path ).get_asset() return unreal.MaterialEditingLibrary.set_material_instance_texture_parameter_value(mi_asset, param_name, tex_asset) unreal.log(“—————————————————“) AssetTools = unreal.AssetToolsHelpers.get_asset_tools() MaterialEditingLibrary = unreal.MaterialEditingLibrary EditorAssetLibrary = unreal.EditorAssetLibrary base_mtl = unreal.EditorAssetLibrary.find_asset_data(“/Game/Environment/Cave/Materials/M_CaveBase”) #Iterate over selected meshes sel_assets = unreal.EditorUtilityLibrary.get_selected_assets() for sm_asset in sel_assets: […]
  • In 3d

    Automating Unreal Engine editor with Python

    Unreal Engine gives you several options to create custom tools for automating tasks in Unreal Editor. You can write C++ code, create Editor Utility Blueprints or write Python. While Blueprints are cool, Python is industry standard for writing pipeline tools and in my opinion is much convenient than doing things with Blueprint nodes in many cases – like dealing with filenames and connecting to things outside Unreal Editor. There are a lot of things you could add to Unreal Editor using editor Blueprints or Python – avoiding repeating manual tasks, automating level building, automating asset management and implementing content creation pipeline. One of the most common things that benefit from automation is dealing with large amount of assets. For example – automatically creating material instances for your meshes with correct texture parameters assigned or automatically renaming your assets according to specific naming convention.Unreal Editor allows you to run python scripts directly from Console or from editor File menu. But much cooler way is to use Editor Utility Blueprints to call your python scripts. Editor Utility Blueprints (or Editor Widget Blueprints if you need fancy UI) are great ways to extent Unreal Editor functionality – there are several useful parent classes available […]