Builtin Library
README.md
presence
Editor presence: who else is in this scene, where they are looking from, and what they are working on, for every client of the world in edit mode. People in their editors and agents in their sub-clients appear alike.
Each client occupies one entity of its own, the way a player occupies its
avatar in play: a temporary, session-scoped PlayerOwned root that the edit
room relays like a player's subtree, takes away with the client when it leaves
(a flip to play, a restart, a disconnect), and the scene never records. It
stands where the client's camera stands, and its EditorPresence component
carries who the client is and what it is doing: its selection, the entities it
is changing, and the call an agent is making. Every other client draws that participant on the entity it
receives: a viewpoint marker in the participant's colour, a name label stating
the activity, and an outline in the same colour around each entity the
participant has selected or is changing.
local EditorPresence = require("@builtin::modules.api.editor.presence")
EditorPresence.ensureRegistered() -- the debug-viz provider that draws the others
EditorPresence.tick(dt) -- publish this client's presence (the editor's per-frame tick)
EditorPresence.publish() -- publish it now
EditorPresence.noteChanged(entityId) -- this client is changing that entity now
for _, p in EditorPresence.participants() do
print(p.name, p.kind, p.activity)
end
local color = EditorPresence.colorOf("agent-1") -- the same colour on every client
| Call | Does |
|---|---|
ensureRegistered() | Registers the provider that draws the other participants. Idempotent. |
tick(dt) | The editor's per-frame tick: every tenth of a second takes away the presence entities of clients that have left which this client was handed, and in edit mode on a bound world publishes this client's presence. |
publish() | Publishes this client's presence now: takes away the presence entities of clients that have left which this client was handed, occupies this client's presence entity, moves it to the viewpoint and states the selection, the entities being changed and the agents' activity. |
noteChanged(id) | Notes that this client changed the entity id now, so its presence states it is changing it for the next two seconds. |
track(id, presence) / untrack(id) | Starts and stops drawing the participant on the presence entity id. |
participants() | One row per remote participant this client draws: its name, kind and activity. |
colorOf(name) | The { r, g, b, a } colour a participant named name is drawn in, the same on every client. |