How to create material and material instance using python ?

i want to create a material and material instance of that material using python in unreal engine.

From the unreal engine python doc i got this:

This is the ‘raw’ way for creating a Material

from unreal_engine.classes import Material
new_material = Material()
new_material.set_name('New Funny Material')
new_material.save_package('/Game/Materials/NewFunnyMaterial')

Even better, you can use the MaterialFactoryNew class

from unreal_engine.classes import MaterialFactoryNew
import unreal_engine as ue

factory = MaterialFactoryNew()
new_material = factory.factory_create_new('/Game/Materials/NewFunnyMaterial')

#destroy the asset
ue.delete_asset(new_material.get_path_name())

But they do not working. thanks in advance.

import unreal

assetTools = unreal.AssetToolsHelpers.get_asset_tools()

assetTools.create_asset(“material_name”, “/Game/Materials”, unreal.Material, unreal.MaterialFactoryNew())

2 Likes

We’re going to need some more detail about the reason why they are not working in order to help;
For example, error codes, unexpected behaviour, etc etc.

thanks a lot!