Add multiplayer¶
Minimal checklist:
- Add a
NetworkComponentto the entities you want replicated (usually on a prefab). Set authority:Serverfor enemies/pickups,Clientfor players,Sharedfor walls. - Set
syncTransform(andsyncSpriteif the sprite changes). - Set
prefabPathto the prefab the other side should instantiate. - Guard simulation in scripts:
local function shouldSimulate()
if not Net.isNetworked() then return true end
return Net.isServer()
end
function Enemy:onUpdate(entity, dt)
if not shouldSimulate() then return end
-- move, animate, collide
end
- Launch with
--server/--client, or use the editor's Play Multiplayer button.
Players are spawned by the engine from the Client-authority template's prefabPath; Lua
cannot instantiate prefabs. Read a client's input on the server with Net.input(entity).
See Engine → Networking, Editor → Multiplayer, and Lua → Net.