Builtin Library
README.md
watch
A watch over the entities holding a set of components. w:changed() answers whether anything a reader of those entities could see is different from the last time it was asked, so a system that derives something from them every frame (an overlay, a validation, a cache) derives it again only when it has to.
Exports
M.new(...) -> Watch: a watch over the entities holding any of the terms. A term is a native component type (ecs.Light) or the name of a script component ("PlayerSpawn"); anything else raises.watch:changed() -> boolean: true when, since the previous call, a native component the watch names was added to or written on an entity, an entity holding one left that set (despawned, or the component removed), or an entity holding any of its terms moved. For script terms it is also true when a component was added to or removed from any entity, or any component's public field was written. The first call answers true.
Usage
local EcsWatch = require("modules.api.engine.ecs.watch")
local lights = EcsWatch.new(ecs.Light, "ReflectionProbe")
task.loop(function()
if lights:changed() then
rebuildOverlay()
end
end)