You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Unreal Python API处理字符串列表:移除路径重复后缀

Unreal Python API 资源路径去重后缀解决方案

你用unreal.EditorAssetLibrary.list_assets()获取的资源路径会带有重复的对象名后缀(比如/Game/ProjectName/Textures/Utility/Texture1_01a.Texture1_01a),可以用以下两种方法清理路径:

方法一:字符串分割(rsplit)

使用rsplit('.', 1)从末尾开始仅分割一次,取前半部分即可去掉后缀:

import unreal

def listAssetPaths():
    EAL = unreal.EditorAssetLibrary
    assetPaths = EAL.list_assets('/Game')
    # 清理路径后缀
    cleaned_paths = [path.rsplit('.', 1)[0] for path in assetPaths]
    return cleaned_paths

# 输出测试
for path in listAssetPaths():
    print(path)

注:如果直接用split('.')会分割路径中所有的.,容易出错,rsplit('.',1)只处理最后一个分隔符,更安全。

方法二:用Unreal内置路径工具(推荐)

Unreal提供了专门的路径处理APIunreal.Paths.get_path(),可以直接返回不带对象名后缀的资源路径,更贴合引擎逻辑:

import unreal

def listAssetPaths():
    EAL = unreal.EditorAssetLibrary
    assetPaths = EAL.list_assets('/Game')
    cleaned_paths = [unreal.Paths.get_path(path) for path in assetPaths]
    return cleaned_paths

内容的提问来源于stack exchange,提问作者Bachalo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 03:15:09