Creating Blueprint node graph for material with Python?

How can one create a new Blueprint material nodes from a python script?

import unreal
material = unreal.Material(‘Material’)

is there an example?

Not sure it’s possible currently. I would assume you need to call


AssetTools.create_asset

Something like


import unreal

def main():
  unreal.AssetTools.create_asset(
    "M_MyMaterial",
    "/Game/Materials/",
    unreal.Material,
    unreal.MaterialFactoryNew(),
    "Python"
  )

if __name__ == '__main__':
  main()

Never had any luck with Factories seeing I always get


AttributeError: 'module' object has no attribute MaterialFactoryNew

You could try see if you have better luck, some other stuff I had missing from my Python seem to have existed for others such as the Undo context.

This is how you create a new blueprint asset:

my_utils.py.PNG


As you can see in vr_project.py, the name of the file that should be created is BP_VRMainCharacter.

In **blueprint.create(name, path, unreal.Character) **the third parameter is the parent class that defines the type of the blueprint being created. So, try changing this to a material type. Which material type? Maybe there is a material type you can find in the Documenation:

https://docs.unrealengine.com/en-US/PythonAPI/index.html


I’m stuck on something else… once the Blueprint is created… is there a way to script adding Event Graph nodes into the Blueprint?

For example, is it possible to create the Event Graph pictured below with python script?

3 Likes

Hey there @gmilligan - did you ever solve your last question? Are you able to use Python to add nodes to the Event Graph somehow?
I’m trying the same thing…

Hello.

Search the documentation for this:

unreal.MaterialEditingLibrary

Methods within to add nodes.