Chapter 19無料公開

【UE×Python】Pythonで全てのアセットのパスを取得する方法(Unreal Engine 5.1)

Yuni-Book
Yuni-Book
2024.05.20に更新
このチャプターの目次

内容

「Unreal Engine」上で、「Python」を使用して全てのアセットのパスを取得する方法

自作関数

### Get All Asset Path in Folder
### /Game/MyFolder
### /Content/MyFolder
def unrealGetAllAssetPathInFolderList(input_path: str = "/Game") -> list[str]:
    return [asset_path for asset_path in unreal.EditorAssetLibrary.list_assets(input_path)]
    # Input:
    # input_path = '/Game/MyFolder'
    # Output:
    # [
    #     '/Game/MyFolder/Blueprints/000/BP_Actor.BP_Actor', 
    #     '/Game/MyFolder/Blueprints/000/BP_EUW.BP_EUW', 
    #     '/Game/MyFolder/Blueprints/000/BP_FunctionLibrary.BP_FunctionLibrary'
    # ]

サンプルプログラム


### Public Library ############################################################
### https://docs.unrealengine.com/5.1/en-US/PythonAPI/#
import unreal

### Function ##################################################################

### Get All Asset Path in Folder
### /Game/MyFolder
### /Content/MyFolder
def unrealGetAllAssetPathInFolderList(input_path: str = "/Game") -> list[str]:
    return [asset_path for asset_path in unreal.EditorAssetLibrary.list_assets(input_path)]
    # Input:
    # input_path = '/Game/MyFolder'
    # Output:
    # [
    #     '/Game/MyFolder/Blueprints/000/BP_Actor.BP_Actor', 
    #     '/Game/MyFolder/Blueprints/000/BP_EUW.BP_EUW', 
    #     '/Game/MyFolder/Blueprints/000/BP_FunctionLibrary.BP_FunctionLibrary'
    # ]

### Main ######################################################################

if __name__ == '__main__': 
    
    #============================================

    print(f"{unrealGetAllAssetPathInFolderList('/Game/MyFolder') = }")
    # LogPython: unrealGetAllAssetPathInFolderList('/Game/MyFolder') = [
    #     '/Game/MyFolder/Blueprints/000/BP_Actor.BP_Actor', 
    #     '/Game/MyFolder/Blueprints/000/BP_EUW.BP_EUW', 
    #     '/Game/MyFolder/Blueprints/000/BP_FunctionLibrary.BP_FunctionLibrary'
    # ]

    #============================================

###############################################################################