Change Parent Material of Multiple Material Instances at Once

Is there a way to change the parent material of multiple material instance all at once? For example, I have 50 material instances and I want them to all have the same parent material.

I have tried scripting it with a blueprint but havent had any luck.

Thanks

2 Likes

In python it’s pretty simple:

import unreal as ue

editor_util = ue.EditorUtilityLibrary()
editor_asset_lib = ue.EditorAssetLibrary()
material_lib = ue.MaterialEditingLibrary()

def SetParentMaterial():
    default_material_path = "Material'/Game/Props/Reparent.Reparent'"
    materialToReparent = editor_asset_lib.load_asset(default_material_path)

    selected_assets = editor_util.get_selected_assets()
    for asset in selected_assets:
        material_lib.set_material_instance_parent(asset, materialToReparent)
        editor_asset_lib.save_loaded_asset(asset,False)

SetParentMaterial()

Be careful: this doesn’t have any check inside it, be sure to select the correct materials and the correct parent path!
Always try with a single asset before running a batch!

3 Likes

hey, I also tried this method and unreal is keep crashing :frowning:

Did you setup python scripting correctly?
It could be tricky if you are using it for the first time.
What error are you getting with the crash?


here’s my crash, and I have no idea :frowning:
engine version is 4.27

Did you set the correct path in “default_material_path” (it has to be the parent material path).
Are you selecting the materials instances to reparent when launching the python script?
That error really doesn’t ring me any bell, I’d make a plugin in C++ and share it with you but right now I’m pretty busy, sorry

1 Like

In the future its best for you to create like this:
-M_MasterMaterial
–MI_MasterInstance
—MI_ChildInstance

That way, you can change the parent on the MI_MasterInstance and cascade down for every other object.

2 Likes

Thanks for searching the answer together :joy: I also made this python code into blueprint, but it also occurred crash :frowning: maybe engine is the problem…

I made you a plugin, it works for me (I hope it does for you too):


MaterialReparenterAutosave.zip (509.5 KB) (Faster)
Automatically saves the materials after replacing the parent

MaterialReparenterUndo.zip (509.0 KB) (Safer)
Mark the assets as modified (and you can undo the operation with CTRL+Z), you need to save them manually to make the edit permanent.

3 Likes

OMG Thanks for the plugin!!
Btw, did you use ‘SetParentInternal’ c++ function for this plugin?
I really want to know what caused the crash, and if you share c++ code for me, it would be also greatful… :smile:

1 Like

I made it with blueprints only, you can open the AssetActionUtility BP in the plugin folder!

The python code was working for me but, as I said, there were no “checks”, casting in python is not the same as BP or C++.

I thought it wasn’t possible to achieve this with BP only, otherwise I wouldn’t have wasted both mine and your time :sweat_smile:

Please don’t forget to mark the post as solution!

Yeah! I checked the BP you gave to me :smile:
The reason why crash occured was because I did not access to material directly, but access it via static mesh actor. Not 100% sure, but the BP you made didn’t occur the crash.

I’m sorry that I did not post the original question, so I cannot mark the solution… :frowning: :sob:

Truly thank u for solving the problem, thanks for spending your precious time for me, you made my day

1 Like

Remember, if there’s the word “actor” it means that they are placed in world, if you have to access assets in editor you need to cast “selected asset” to its specific class and then use the function that you need (in this case to replace the parent)

Oh, I’m sorry, I didn’t notice it.
Don’t worry, I flagged the post and a mod has already marked it for you!

You are very welcome, I’m happy that it worked and I shared it because I think it could be useful to other useful to other users in the future (because this is an issue that could occur very easily).
That’s why imho it’s important to “mark a thread as solved”, when I’m looking for a solution I try to avoid posts that don’t have one (sometimes they can point you the right direction where to look but you have to find a way by yourself!)

Have a nice day!
If you are interested in editor scripting, I took a useful course that I would recommend that covers C++, BP and Python!

1 Like

still crash if some actors are referencing any of those material instance.
We need to remove any actors in your level before changing the parent.

Nice Solution!

A very handy plugin, thank you so much Ares9323!

1 Like

Has anyone gotten the plugin from @Ares9323 to work with material instances/interfaces as the parent? Nearly every time I try it with those my editor crashes.

Which engine version are you using?
Have you tried using it with few instances at a time? (There could be an issue with some material in particular that may cause your crashes)

Of course now when I try to reproduce it, it works fine. :man_shrugging: I’m using 5.1.1 at the moment.

1 Like

I have found that, if I have the asset loaded in the editor and I try to change its parent, UE crashes.

I first have to remove the asset from the editor and then change its parent.

1 Like