UE启动加载python脚本


启动脚本路径: 我的文档\UnrealEngine\python\init_unreal.py

通过环境变量增加ue插件路径: os.environ['UE_ADDITIONAL_PLUGIN_PATHS'] = 'D:/Users/Documents/UnrealEngine/Plugins;D:/Users/Documents/UnrealEngine/Plugins/UE5.2;'

启动脚本里需要加入下方代码,不然pyside相关的窗口会出异常,同时pyside的窗口必须使用全局变量接着,不然会被python的垃圾回收机制给干掉

from Qt import QtWidgets, __binding__

def __QtAppTick__(delta_seconds):
    QtWidgets.QApplication.sendPostedEvents()


if __name__ == '__main__':
    unreal_app = QtWidgets.QApplication.instance()
    if not unreal_app:
        unreal_app = QtWidgets.QApplication([])
        tick_handle = unreal.register_slate_post_tick_callback(__QtAppTick__)
        __QtAppQuit__ = partial(
            unreal.unregister_slate_post_tick_callback, tick_handle)
        unreal_app.aboutToQuit.connect(__QtAppQuit__)

评论
  目录