Source code for cgl.plugins.unreal.utils.engine

import logging
import os
import platform
import re
from cgl.core.config.query import AlchemyConfigManager

CFG = AlchemyConfigManager()
if hasattr(CFG, "unreal_config"):
    UE_CONFIG = CFG.unreal_config
else:
    UE_CONFIG = {}


[docs] def get_unreal_version_number(): """ Gets the version number of the Unreal Engine being used Returns: """ return UE_CONFIG.get("version")
[docs] def get_unreal_exe_path(): """ Gets the full path to the UnrealEditor.exe application """ ue_version = CFG.unreal_config.get("version") if platform.system() == "Windows": exe_path = r"C:\Program Files\Epic Games\UE_{}\Engine\Binaries\Win64\UnrealEditor.exe".format( ue_version ) if not os.path.exists(exe_path): logging.error( "ALC_ENGINE path {} does not exist, " "please install it with the epic games launcher".format(exe_path) ) return None return exe_path else: logging.info( "Not On Windows. We haven't implemented get_unreal_exe_path() for this OS yet" ) return None
[docs] def get_unreal_python_path(): """ Get the full path to the python.exe version for this unreal version. Returns: ue_python (str): Full path to the python.exe for this unreal version """ version = get_unreal_version_number() ue_python = r"C:\Program Files\Epic Games\UE_{}\Engine\Binaries\ThirdParty\Python3\Win64\python.exe".format( version ) if os.path.exists(ue_python): return ue_python return
[docs] def get_unreal_plugins_path(): """ Gets the path to the Unreal Plugins folder Returns: plugins_dir (str): Path to the Unreal Plugins folder """ unreal_exe_path = get_unreal_exe_path() if unreal_exe_path: engine_dir = os.path.dirname(os.path.dirname(os.path.dirname(unreal_exe_path))) plugins_dir = os.path.join(engine_dir, "Plugins") return plugins_dir
[docs] def get_unreal_config_path(): unreal_exe_path = get_unreal_exe_path() if unreal_exe_path: engine_dir = os.path.dirname(os.path.dirname(os.path.dirname(unreal_exe_path))) config_dir = os.path.join(engine_dir, "Config") return config_dir
[docs] def get_unreal_marketplace_plugins_dir(): """ Gets the path to the Unreal Marketplace plugins folder Returns: plugins_dir (str): Path to the Unreal Marketplace plugins folder """ unreal_plugins_path = get_unreal_plugins_path() if unreal_plugins_path: plugins_dir = os.path.join(unreal_plugins_path, "Marketplace") return plugins_dir
[docs] def get_engine_version(): """ Gets the version of unreal engine being used from the ALC_ENGINE env variable Returns: version_number (str): The version number of the engine being used. ex. "02.25" """ unreal_exe_path = get_unreal_exe_path() if unreal_exe_path: match = re.search("UE_(?P<major>[0-9])\.(?P<minor>[0-9]*)", unreal_exe_path) if not match: logging.error( f"Could Not Find Engine Version From Unreal Path\nUnreal Path: {unreal_exe_path}" ) return else: major = match.group("major") minor = match.group("minor") version_number = f"{major}.{minor}" return version_number
if __name__ == "__main__": print(UE_CONFIG)