Skip to main content

Hooks

Hooks allow you full control of scheduling logic, allowing YetAnotherNet to be used for any game structure whether ECS or not.

When you use createHook, it will return a beginFrame and endFrame function which should be called at the beginning and end of each frame respectively.

It's expected, and recommended that you still run your scheduling code on RunService.Heartbeat, otherwise you may run into unexpected behavior. If you know what you're doing, you can ignore this warning.

local RunService = game:GetService("RunService")

local YetAnotherNet = require("@packages/YetAnotherNet")
local routes = require("@shared/routes")

local myRoute = routes.myRoute

local beginFrame, endFrame = YetAnotherNet.createHook({ Route })
RunService.Heartbeat:Connect(function()
beginFrame()

myRoute:send(...)
for i, player, data in myRoute:query() do
-- Do something
end

endFrame()
end)