Detaching an entity¶
The Detached tag takes an entity and its descendants out of the running
game and keeps them, for an undo stack or an object pool. In the same frame
they stop colliding, answering raycasts, drawing and playing sound. Removing
the tag brings them back, and bodies and welds rebuild on the next physics
step. Destroy deletes an entity for good.
-- Server script in a part: take a brick out of the game for 2 seconds.
local brick = World.Spawn({ Name = "Brick", Parent = World })
brick:Add(Component.Detached)
print(World.Find("Brick") == brick) -- prints true
task.wait(2)
brick:Remove(Component.Detached)
print(brick:Has(Component.Detached)) -- prints false
A detached entity keeps its parent, name and components. Find and
WaitFor still find it, and Children still lists it. An entity moved under a
detached parent becomes detached too. World.Query skips detached entities
unless the query names Detached.
Only the server, or a client that owns the entity, can add or remove the tag.