From c4486234710a41407f83c407396362bcd51a995d Mon Sep 17 00:00:00 2001 From: Vysyr Date: Fri, 4 Sep 2026 23:42:07 +0200 Subject: [PATCH] organization script --- {scripts => Content/Python}/helloworld.py | 0 Content/Python/organize_content.py | 44 +++++++++++++++++++++++ 2 files changed, 44 insertions(+) rename {scripts => Content/Python}/helloworld.py (100%) create mode 100644 Content/Python/organize_content.py diff --git a/scripts/helloworld.py b/Content/Python/helloworld.py similarity index 100% rename from scripts/helloworld.py rename to Content/Python/helloworld.py diff --git a/Content/Python/organize_content.py b/Content/Python/organize_content.py new file mode 100644 index 0000000..7e63947 --- /dev/null +++ b/Content/Python/organize_content.py @@ -0,0 +1,44 @@ +import re, unreal + +FOLDERS = { + "material": "Materials", + "player": "Characters/Player", + "enemy": "Characters/Enemy", + "particle": "Effects", +} +CLASS_FOLDERS = { + "World": "Maps", + "LevelSequence": "Sequences", +} +PREFIXES = { + "World": "", + "Material": "M_", + "MaterialInstanceConstant": "MI_", + "StaticMesh": "SM_", + "SkeletalMesh": "SK_", + "Blueprint": "BP_", + "NiagaraSystem": "NS_", + "LevelSequence": "LS_", +} + +lib = unreal.EditorAssetLibrary +for path in lib.list_assets("/Game", recursive=True): + path = path.split(".")[0] + name = path.rsplit("/", 1)[-1] + data = lib.find_asset_data(path) + cls = str(data.asset_class_path.asset_name) + + # instance assets are renamed after their parent, not their own name + if cls == "MaterialInstanceConstant": + parent = lib.load_asset(path).get_editor_property("parent") + base = re.sub(r"^(M_|MI_)", "", parent.get_name()) if parent else name + suffix = name[len(base):] if name.lower().startswith(base.lower()) else "" + name = base + (f"_{suffix.capitalize()}" if suffix else "") + + name = re.sub(r"^(" + "|".join(p for p in PREFIXES.values() if p) + ")", "", name) + name = PREFIXES.get(cls, "") + name + + folder = CLASS_FOLDERS.get(cls) or next((f for k, f in FOLDERS.items() if k in name.lower()), "Misc") + dest = f"/Game/{folder}/{name}" + if path != dest: + lib.rename_asset(path, dest)