-
-
Notifications
You must be signed in to change notification settings - Fork 216
/
Copy pathCreateInstancesOfSelectedMaterial.py
51 lines (36 loc) · 1.43 KB
/
CreateInstancesOfSelectedMaterial.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# _
# (_)
# _ __ ___ __ _ _ __ ___ ___ _ __ _ ___ _ __ ___
# | '_ ` _ \ / _` | '_ ` _ \ / _ \| '_ \| |/ _ \ '_ ` _ \
# | | | | | | (_| | | | | | | (_) | | | | | __/ | | | | |
# |_| |_| |_|\__,_|_| |_| |_|\___/|_| |_|_|\___|_| |_| |_|
# www.mamoniem.com
# www.ue4u.xyz
#Copyright 2022 Muhammad A.Moniem (@_mamoniem). All Rights Reserved.
#
import unreal
#Set the instances count needed
totalRequiredInstances = 10
#General variables, will be auto set
newAssetName = ""
sourceAssetPath = ""
createdAssetsPath = ""
@unreal.uclass()
class EditorUtil(unreal.GlobalEditorUtilityBase):
pass
@unreal.uclass()
class MaterialEditingLib(unreal.MaterialEditingLibrary):
pass
editorUtil = EditorUtil()
materialEditingLib = MaterialEditingLib()
selectedAssets = editorUtil.get_selected_assets()
factory = unreal.MaterialInstanceConstantFactoryNew()
asset_tools = unreal.AssetToolsHelpers.get_asset_tools()
for selectedAsset in selectedAssets:
newAssetName = selectedAsset.get_name() + "_%s_%d"
sourceAssetPath = selectedAsset.get_path_name()
createdAssetsPath = sourceAssetPath.replace(selectedAsset.get_name(), "-")
createdAssetsPath = createdAssetsPath.replace("-.-", "")
for x in range(totalRequiredInstances):
newAsset = asset_tools.create_asset(newAssetName %("inst", x+1), createdAssetsPath, None, factory)
materialEditingLib.set_material_instance_parent(newAsset, selectedAsset)