Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commit44fd9e59bd

README.md

entityOps

Operate on scene entities — spawn, instantiate content, change state, swap, and navigate the hierarchy. Every tool resolves targets by entity name or id (single, a list, or the records scene.find returns) or by a scene.find query ({ name = { "wheel" } }, { component = { "Light" } }, { under = { "car" } }) that names a selection without looking it up first, and asset inputs by a name / path / identity string that the tool resolves and reports back canonically — so the caller never needs to know an asset's exact identity up front.

Finding and reading entities is the scene toolbox (scene.find, scene.tree, scene.summary); this toolbox is the operating surface.

Spawn + instantiate

  • spawn — spawn entities from a template: name the components they carry and their field values, plus a transform. Authored (serializing) components only. Pass a { defaults, items } list to spawn MANY in one call with shared defaults and per-item overrides — a six-walled room is one call, not six — validated whole before any entity is created.
  • fromAsset — instantiate an existing asset (bundle / avatar / mesh / material / texture, or anything with an :instantiate()): resolves a name/path/identity string, dispatches by category, and reports the canonical asset it hit. Controls the live link and synced flags.

State + hierarchy

  • modify — delete / enable / disable / internal / temporary / reparent / rename, over one or many entities.
  • swap — replace an entity with another entity that already exists in the scene (moves it into the target's slot).
  • addComponents — attach component(s) with setup data to one or many entities; create spawns missing ones.
  • removeComponents — detach component(s) from one or many entities, reporting per entity what was removed and what was absent.
  • component — inspect a component TYPE's schema: its public fields (name + type + current value), methods, and lifecycle hooks — so you set fields that exist instead of guessing. Reach for it before addComponents / spawn.
  • roots — find the root ancestor of one or many entities.

Transform + copy

  • transform — move, rotate and scale: absolute sets, relative offset / rotate / scaleBy, and grid snapping. With no ops it is a pure read of the current transform.
  • duplicate — copy entities, one at a time or as a numbered run stepped along an accumulating offset.

Addressing a set you built

Every tool here resolves targets by query as well as by name or id, so a set can be operated on without retaining a single id. Tag the set as you build it, then address it by that tag:

-- Build the set in one call, tagged.
entityOps.spawn({
  defaults = { components = { Model = { model = "cube" } },
               attributes = { group = "roomA" } },
  items    = { { name = "wall_n", position = { 0, 1, -2 } },
               { name = "wall_s", position = { 0, 1,  2 } } },
})

local set = { attribute = { name = "group", value = "roomA" } }

entityOps.transform(set, { offset = { 0, 5, 0 } })   -- move the whole set
renderLayer.set(set, "shell")                        -- re-layer the whole set
entityOps.modify(set, { delete = true })             -- remove the whole set

The tag is an ordinary entity attribute, so it persists with the scene and is as much a part of the content as a name is.

To see what is already present rather than what you made, scene.find with no search axis returns the whole live population, and include = { "transform", "componentValues", "attributes" } annotates each hit — one call, no follow-up per entity.