State visibility
Visibility decides which match scenes, entities and components a player's machine receives. The server still runs the full match. A client predicts with the state it is allowed to have, and authoritative corrections supply consequences that its partial simulation could not reproduce.
The server's own machine is the exception: its player sees the whole match, as the server does, so that machine runs each tick once. Its views and local handlers see hidden entities and components too, and hear every event the match sends. Visibility keeps state from the other machines.
The API names below are provisional. Visibility applies to entities and whole components. To hide a card's face while keeping its back public, put the face in a separate component; individual fields do not have visibility rules.
Share an audience
An Audience is a set of players. Audience.All includes everyone and Audience.None includes nobody. Audience.Only(player) selects one player; Audience.From(players) takes a List<PlayerID>. An audience value has Add(player), Remove(player) and Contains(player), and two audiences are equal (==) when they have the same players.
A VisibilityGroup gives many entities one live audience:
singleton Region { VisibilityGroup group; }
component Block { int kind; }
scene Main { }
event(Spawned) Setup(mut Region region, with Main)
{
region.group = Visibility.CreateGroup(Audience.None);
Spawn(Block { kind = 1 }, Visibility { group = region.group });
Spawn(Block { kind = 2 }, Visibility { group = region.group });
}
event(PlayerJoined joined) Admit(Region region)
{
Visibility.Set(region.group, Audience.Only(joined.player));
}Visibility.Set(group, audience) replaces the audience for every entity using that group. Build an audience with all interested players before setting it. Changing an Audience variable after CreateGroup or Set does not change the group until another Set call.
For a voxel world, make each chunk an entity with a group of its own, and update the group's audience as players approach or leave. A player's machine is then sent the chunks it walks into and nothing of the rest; chunks nobody is near can be saved and destroyed (Saving the match). For distant players on a map, give each player entity its own group and compute the observers in match code. The engine supplies the mechanism; the game chooses distances, teams, occlusion and update frequency.
An entity without Visibility is public, subject to its enclosing scene. A default Visibility uses an all-player group. Visibility.DestroyGroup(group) makes existing references to that group see nobody; a later group does not reuse the stale handle.
Restrict a scene
Scenes use the same groups. Put Visibility on the loaded root:
var group = Visibility.CreateGroup(Audience.Only(player));
var hand = Scene.Load(Hand { player = player }, Visibility { group = group });The root's group limits every entity owned by that scene, including entities
spawned later. Visibility.Set(group, audience) updates them together. Use
Audience.None for a server-only scene, or share a group across multiple scenes
and entities. Scene ownership still controls loading and unloading; destroying
a group conceals its members without unloading them.
Hide a component
Keep public and private data in separate components:
component Card { int back; }
component CardFace { int rank; int suit; }
event(Spawned) ProtectFace(Owner owner, mut Visibility visibility, with CardFace)
{
visibility.Set<CardFace>(Audience.Only(owner.player));
}The entity must carry Visibility. Set the restriction during construction, before initial state can be published; waiting for the next system tick can expose the initial component. Update the policy when the holder changes. visibility.Set<CardFace>(audience) restricts the whole component. It also accepts a shared group: visibility.Set<CardFace>(handGroup). visibility.Reset<CardFace>() removes that override, so the component follows the entity again.
The effective audience is the intersection of the scene root's group, the entity's group and the component's restriction. An entity or component cannot broaden its enclosing scope. Ordinary transform parenting does not inherit visibility. A component outside a recipient's audience is absent on that client, including from queries and Has<T>(); without CardFace can therefore match there.
For poker, keep the public card back on the entity and restrict CardFace to the holder. Put an undealt deck in an audience of nobody, or a private scene with no members. Membership, group contents and component overrides are server policy; clients receive their permitted state rather than the policy's private membership data.
Time.seed is public, and default Random state derives from it. Hiding card faces alone does not make a shuffle derived from that public seed unpredictable. A secret shuffle needs a private seed supplied authoritatively, with its RNG state and undealt deck kept restricted.
Spatial parents
A public child can remain visible while its transform parent or the parent's Transform is hidden. The projected hierarchy cuts that private link. Where the visible subtree contains a permitted Transform, an internal placement anchor preserves its composed placement, including rotated nonuniform scales. The child's local transform values stay unchanged; no private parent entity or component payload is copied.
That derived placement is part of the permitted spatial state. A visible entity with no permitted Transform in its visible subtree does not receive an anchor just because its parent has one. Calling world.LocalToWorld on such an entity in a partial client can omit hidden influence. world.Parent reflects the projected links, so a concealed parent can appear null. Choose visibility for spatial state according to what players may infer from visible children.
Availability and actual lifetime
Use local event(Shown) to initialize presentation when an entity or a handler's required components become available. It runs for arrivals, reveals and genuine spawns. local event(Hidden) removes presentation when that availability ends, and reads the last permitted state. The same forms accept verified Shown and verified Hidden.
local event(Spawned) and local event(Destroyed) describe actual match lifetime. Joining, revealing an existing entity or receiving a repair does not fabricate either event. A concealed entity's later destruction does not announce its death to a recipient who could not see it at destruction. Forgotten remains the cleanup hook for local fields.
On the server's own machine, which sees the whole match, an entity only leaves as the match destroys it, so its handlers hear Destroyed rather than Hidden while its player keeps up with the server. Where that player takes the server's world whole (after a new build takes over, or once it fell behind), an entity that went in the ticks it skipped is Hidden there, and one that came is Shown without Spawned, as for a joining player. Another player's machine hears Hidden for an entity hidden from it, even when the match destroys it in the same tick, since it couldn't see it at its destruction. Its predicted handlers hear what its own run of a tick did, which can be the destruction of an entity the server hid in that tick; its verified handlers then hear Hidden. To let go of what local code keeps for an entity however it leaves a machine, use Forgotten, which every machine sends once.
Each handler's component requirements determine its availability. A handler reading Card can remain active while a handler reading CardFace becomes hidden. A Shown handler should prepare resources; a true Spawned handler can play the effect for a new object.
Provisional delivery rule: availability follows the endpoints delivered to local presentation. Changes inside one tick or between frames coalesce to their final availability, so adding, removing and adding a component before a frame cannot leave its presentation released. A correction that restores an entity or component runs Shown again; an unchanged replay does nothing. Predicted and verified handlers follow separate presentation endpoints, and their queries read the corresponding old or new endpoint. A local rebuild clears this history and prepares available objects again, so Shown initialization should reuse or replace existing resources safely.
In a sharded world
In a sharded world, a group means the same on every shard: an entity in it is shown to the same players on whichever shard has it, and each shard sends its own players only what they may see. The groups are kept with the first shard. Code on another shard that creates, changes or destroys a group waits on the border for them, and other shards see the change a tick or two later.
Consequences across a visibility boundary
The server may simulate a hidden object affecting a public one. The client receives the corrected public result; it does not need the hidden cause. Design public state to contain the consequences players need, such as damage, a revealed projectile or a public combat log.
Custom local event(...) and local event(verified ...) handlers hear events produced by the client's permitted simulation. They are not a general authoritative server-to-audience event channel. A hidden system's custom event is not forwarded to other players, and neither is one a command sends: the compiler warns at a Send in a command when the event has a local handler, because only the server's own machine would hear it. Put what the other players should see into a component or singleton they may see, and let a local handler of Changed<...>, or a view, show it. Choose public fields and input payloads deliberately, and decide what each command publishes.
Commands execute only on the authoritative server in this path; clients receive permitted results. A match that hides state also ends with the machine that runs it: no player's machine has the whole match, and none may be given it, so hostMigration = true is an error in a game that uses visibility. Run such a match on a dedicated or hosted server when it has to outlast any one player.
Match task continuations and opaque Resident state stay on the authoritative server in a visibility-enabled match. They are not copied into projected clients. Publish the state needed for presentation and prediction in ordinary permitted components. Public match singletons remain public, so keep per-entity secrets in components or private scenes.
The physics packages keep their worlds in [Native] fields, the library's own state: Box2D's Physics.image, Box3D's Resident, both packages' handles, collider and rewind-history lists. A client doesn't receive those. Its world arrives with them at zero, as on a shard an entity comes to, and the package makes its physics world again from the bodies the client has. A hidden body is absent from that world, so what it does to visible ones comes with the server's corrections. Rewind history starts again on a client after each correction, so a client's own Physics.Rewind can fail where the server's succeeds: hits are decided on the server.
On a client, Visibility.CreateGroup can't number a group: the server does. What a client's own tick puts in a group without the client's player stays out of its projection, as it's out of the server's projection for it; what it puts in one with its player is visible to it. Visibility.Set does nothing there, so something coming into or going out of sight always arrives as a correction.
See Scenes for scene ownership and audiences and Networking for verification and corrections.