ExecuteInGameThread

ExecuteInGameThread

ExecuteInGameThread 使用 ProcessEvent 钩子或 EngineTick 钩子在游戏线程中执行代码。

游戏有空闲执行时间时,会尽快执行该代码。

参数

# 类型 说明
1 function 游戏有空闲执行时间时要执行的回调
2 EGameThreadMethod (可选)使用的执行方式。默认采用配置中的默认方式。

示例

-- Basic usage (uses default method from config)
ExecuteInGameThread(function()
    print("Hello from the game thread!\n")
end)

-- Explicit EngineTick method (once per frame)
if EngineTickAvailable then
    ExecuteInGameThread(function()
        print("Hello from EngineTick!\n")
    end, EGameThreadMethod.EngineTick)
end

-- Explicit ProcessEvent method
if ProcessEventAvailable then
    ExecuteInGameThread(function()
        print("Hello from ProcessEvent!\n")
    end, EGameThreadMethod.ProcessEvent)
end

相关全局变量

  • EngineTickAvailable - 表示 EngineTick 钩子是否可用的布尔值
  • ProcessEventAvailable - 表示 ProcessEvent 钩子是否可用的布尔值

注意事项

  • 如果指定方式不可用,而另一种方式可用,函数会自动回退到另一种方式
  • 可以通过 UE4SS-settings.ini 中的 DefaultGameThreadExecutionMethod 配置默认方式
  • ProcessEvent 调用频繁(每帧多次),EngineTick 每帧调用一次

原文:docs/lua-api/global-functions/executeingamethread.md · 固定提交 560411f18512 · 来源与 MIT 许可