如何找到当前计算机所有的UnrealEngine安装位置

    使用UnrealEngine主要有两种方式:1.通过EpicGameLauncher安装 2. 通过源代码自行编译。

1. 通过EpicGameLauncher安装时,安装的版本和安装位置记录在注册表的这个位置:

  HKEY_LOCAL_MACHINE\SOFTWARE\EpicGames\Unreal Engine

    每个版本都会有一个子目录,对应版本的安装路径在这个子目录的InstalledDirectory属性中:

image

 2. 通过源代码安装

    如果你的项目是通过源代码编译的引擎来操作的,那么在uproject文件中会保存该引擎的guid,比如:

"FileVersion": 3,
"EngineAssociation": "{9453D6AB-4C8B-9CBE-4B26-8AA51A358E17}",
"Category": "Samples",

     这个就是源代码引擎的guid,可以通过这个guid找到源代码引擎所在位置。这些源代码引擎的注册表位置是:

HKEY_CURRENT_USER\Software\Epic Games\Unreal Engine\Builds

    这个Builds目录下的键值就是以这些GUID作为名词,如:

image

    注意键名词是有大括号的哈,查找用的python脚本:

import os
import sys
import json
import winreg
import argparse
import re

def find_ue_path(project_path):
    """
    查找 Unreal Engine 路径
    1. 从 .uproject 文件读取 EngineAssociation
    2. 如果是 GUID 格式,尝试从注册表查找
    3. 如果是版本号格式,尝试构造默认路径
    """
    if not project_path or not os.path.exists(project_path):
        return None
    
    try:
        with open(project_path, 'r') as f:
            project_data = json.load(f)
            engine_association = project_data.get("EngineAssociation")
            
            if not engine_association:
                return None
            
            # 检查是否是 GUID 格式(包含大括号)
            if isinstance(engine_association, str) and re.match(r"^\{[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}\}$", engine_association):
                # 在注册表中查找 GUID
                for hive in [winreg.HKEY_CURRENT_USER, winreg.HKEY_LOCAL_MACHINE]:
                    try:
                        key_path = r"Software\Epic Games\Unreal Engine\Builds"
                        with winreg.OpenKey(hive, key_path) as key:
                            try:
                                path = winreg.QueryValueEx(key, engine_association)[0]
                                if os.path.exists(path):
                                    return path
                            except:
                                pass
                    except:
                        pass
            
            # 尝试作为版本号处理
            if isinstance(engine_association, str):
                # 尝试在注册表中查找版本号
                for hive in [winreg.HKEY_LOCAL_MACHINE]:
                    try:
                        key_path = r"SOFTWARE\EpicGames\Unreal Engine"
                        with winreg.OpenKey(hive, key_path) as key:
                            try:
                                # 打开版本号子键
                                with winreg.OpenKey(key, engine_association) as version_key:
                                    path = winreg.QueryValueEx(version_key, "InstalledDirectory")[0]
                                    if os.path.exists(path):
                                        return path
                            except:
                                pass
                    except:
                        pass
    except Exception as e:
        print(f"处理项目文件时出错: {e}", file=sys.stderr)
    
    return None

def main():
    parser = argparse.ArgumentParser(description='查找 Unreal Engine 路径')
    parser.add_argument('--project', help='.uproject 文件路径')
    args = parser.parse_args()
    
    ue_path = find_ue_path(args.project)
    
    if ue_path:
        print(ue_path)
        return 0
    else:
        print("找不到 Unreal Engine 路径", file=sys.stderr)
        return 1

if __name__ == "__main__":
    sys.exit(main())
bodong@BODONG-PC12 MINGW64 /g/TMTechDemos (master|SPARSE)
$ python ./find_ue_path.py --project ./TMTechDemos.uproject
I:/UnrealEngine-EpicGames

bodong@BODONG-PC12 MINGW64 /g/TMTechDemos (master|SPARSE)
$ python ./find_ue_path.py --project 'g:/UnrealProjects/TPSDemo/TPSDemo.uproject'
C:\Program Files\Epic Games\UE_5.4

 

posted @ 2025-09-28 17:40  bodong  阅读(37)  评论(0)    收藏  举报