Skip to content

Commit ac1a10f

Browse files
committed
- add the unify asset duplicates script
- update the README file
1 parent 62cc27b commit ac1a10f

2 files changed

Lines changed: 63 additions & 0 deletions

File tree

Assets/UnifyAssetDuplicates.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# _
2+
# (_)
3+
# _ __ ___ __ _ _ __ ___ ___ _ __ _ ___ _ __ ___
4+
# | '_ ` _ \ / _` | '_ ` _ \ / _ \| '_ \| |/ _ \ '_ ` _ \
5+
# | | | | | | (_| | | | | | | (_) | | | | | __/ | | | | |
6+
# |_| |_| |_|\__,_|_| |_| |_|\___/|_| |_|_|\___|_| |_| |_|
7+
# www.mamoniem.com
8+
# www.ue4u.xyz
9+
#Copyright 2019 Muhammad A.Moniem (@_mamoniem). All Rights Reserved.
10+
#
11+
12+
import unreal
13+
14+
workingPath = "/Game/"
15+
16+
@unreal.uclass()
17+
class EditorUtil(unreal.GlobalEditorUtilityBase):
18+
pass
19+
20+
@unreal.uclass()
21+
class GetEditorAssetLibrary(unreal.EditorAssetLibrary):
22+
pass
23+
24+
editorUtil = EditorUtil()
25+
editorAssetLib = GetEditorAssetLibrary()
26+
27+
selectedAssets = editorUtil.get_selected_assets()
28+
selectedAsset = selectedAssets[0]
29+
30+
selectedAssetName = selectedAsset.get_name()
31+
selectedAssetPath = selectedAsset.get_path_name()
32+
33+
allAssets = editorAssetLib.list_assets(workingPath, True, False)
34+
allAssetsCount = len(allAssets)
35+
36+
assetsMatching = []
37+
38+
with unreal.ScopedSlowTask(allAssetsCount, selectedAssetPath) as slowTask:
39+
slowTask.make_dialog(True)
40+
for asset in allAssets:
41+
_assetData = editorAssetLib.find_asset_data(asset)
42+
_assetName = _assetData.get_asset().get_name()
43+
44+
if (_assetName == selectedAssetName):
45+
if (asset != selectedAssetPath):
46+
print ">>> There is a duplicate found for the asset %s located at %s" % (_assetName, asset)
47+
_assetLoaded = editorAssetLib.load_asset(asset)
48+
assetsMatching.append(_assetData.get_asset())
49+
if slowTask.should_cancel():
50+
break
51+
slowTask.enter_progress_frame(1, asset)
52+
53+
54+
if (len(assetsMatching) != 0):
55+
editorAssetLib.consolidate_assets(selectedAsset, assetsMatching)
56+
print ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
57+
print ">>> The unifing process completed for %d assets" % len(assetsMatching)
58+
print ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
59+
else:
60+
print ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
61+
print ">>> There were no duplicates found for the selected asset"
62+
print ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Don't forget to follow this repo, [YouTube](http://www.youtube.com/channel/UCBBc
2020

2121
- **[ReportUnusedAssets.py](https://github.com/mamoniem/UnrealEditorPythonScripts/blob/master/Assets/ReportUnusedAssets.py)** Running this script will look through all the project folders, and add to the log the assets that were found not in a use, or in another word, the assets that have no dependency with any other project files.
2222
- **[DeleteUnusedAssets.py](https://github.com/mamoniem/UnrealEditorPythonScripts/blob/master/Assets/DeleteUnusedAssets.py)** Running this script will look through all the project folders, and delete the assets that were found not in a use, or in another word, the assets that have no dependency with any other project files. Note that, running this script won't show a confirmation message or accepting dialogue box, it will force delete the assets right a way, so make sure to evaluate the change before submitting to your repo.
23+
- **[UnifyAssetDuplicates.py](https://github.com/mamoniem/UnrealEditorPythonScripts/blob/master/Assets/UnifyAssetDuplicates.py)** Run on a selected single asset in order to look through the project for similar assets with the same name, and will remove all of them, and replace all their references with the selected one. This is a very common case if for example have added several packs or assets to the project and you will end up with several files (textures, materials or such) that have the same exact name and parameters *(add Paragon characters for example to a single project could result that)*, but a unique version coming from each imported pack; and there it come the usage of that script in unifying them.
2324

2425
## Materials ##
2526
- **[CreateInstancesOfSelectedMaterial.py](https://github.com/mamoniem/UnrealEditorPythonScripts/blob/master/Materials/CreateInstancesOfSelectedMaterial.py)** Run on a selected single or multiple Material file(s) in order to generate material instances of it/them. The number of the final generated instances count can be set within the script before running, by changing the value of the variable *totalRequiredInstances*

0 commit comments

Comments
 (0)