Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

NotifyOnNewObject

NotifyOnNewObject(className, fn [, fast])

新创建了某个类(含子类)的对象时调用 fn。

参数

#类型说明
1string类名,规则同 FindFirstOf
2functionfn(obj),obj 是新对象的 UObject 包装
3boolean可选。true 用快速通道,每约 16 ms 扫描一次(默认约 50 ms)。见 FastLoop

说明

  • 实现方式是定期比较全局对象表每个槽位的(指针,序号),引擎会复用释放的槽位,所以序号也参与比较;在两次扫描之间创建又销毁的对象会漏掉。
  • 对象刚创建时可能还没初始化完。需要读写属性的话,用 ExecuteWithDelay 稍后再处理。
  • 默认对象(CDO)不触发。
  • 模组被禁用或重新加载时自动取消。

示例

NotifyOnNewObject("PlayerController", function(pc)
  ExecuteWithDelay(500, function()
    if pc:IsValid() then Log.info("new controller: " .. pc:GetPathName()) end
  end)
end)