Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commite8beb5604c

README.md

prefab.edit (procNode)

Edit the entity records of a prefab, the reusable entity template a spawn copies, and answer the result: add a component to the root, add a child entity, move entities under another, write one entity's id into another's component, join records on, place another prefab under an entity at a local pose, or look an entity up by name. The prefab wired in is left as it was. The parts a graph builds and parents itself are elements: elements.entity makes one and elements.link parents it under another.

prefab.add_component, prefab.entity, prefab.parent, prefab.link, prefab.place and prefab.find each call this node with their what; call those for the single edits, and this node for join. Each edit runs on a copy of the record list (the Luau module edit.module beside it):

  • add_component appends { type, data } to the root's components; an empty type is an error.
  • entity appends a record named name (or fallback when name is empty), with id add_<n> (n the record count before it), under the entity parent names, or under the root when parent is empty or names no entity.
  • parent moves every record named name, the root excepted, under the entity parent names (or the root).
  • link writes the id of the first entity named to into data[field] of the first type component on the first entity named name, adding that component when the entity holds none; field empty takes "target", and an empty or unknown name is an error.
  • join appends the records of children after the prefab's own.
  • place appends the records of children renumbered: each takes the id place<n>_<its id> (n the record count before it, raised past any id the prefab already holds), its parent_id and every string in its components' data that names a placed id take the new ids, and each placed root hangs under the entity parent names (the root when parent is empty; an unknown name is an error), standing at its own pose inside the frame position, rotation and scale pose.
  • find answers { id, found }: the id of the first record named name, or fallback and found = false.

Inputs

  • what (String, default "find"; one of add_component, entity, parent, link, join, place, find). Which edit runs.
  • prefab (Prefab). The prefab edited: its record list is the first record, the root, then every entity added.
  • name (String, default ""). The entity the edit names: the new child's name (entity), the entities moved (parent), the entity that holds the reference (link) or the entity looked up (find).
  • fallback (String, default ""). The name an empty name takes (entity), or the id find answers when no entity carries the name.
  • parent (String, default ""). The name of the entity a child hangs under (entity, parent, place). Empty takes the root; a name the prefab does not carry takes the root (entity, parent) or is an error (place).
  • to (String, default ""). The name of the entity pointed at (link).
  • type (String, default ""). The component type added (add_component) or written into (link).
  • field (String, default "target"). The key inside the component's data the referenced entity's id lands under (link).
  • data (Record, optional). The component's fields (add_component). Unwired, the component takes its schema's defaults.
  • children (List<Record>, optional). The records appended after the prefab's own (join), or the records of the prefab placed (place).
  • position (List<Float>, default { 0, 0, 0 }). The local position the placed prefab's root stands at under its parent (place).
  • rotation (List<Float>, default { 0, 0, 0, 1 }). The local rotation of the placed prefab's root, a quaternion (x, y, z, w) (place).
  • scale (List<Float>, default { 1, 1, 1 }). The local scale of the placed prefab's root (place).

Outputs

  • value. The new record list, or { id, found } for find. A caller makes a prefab of a record list as { records = list }.
local extra = g.prefab.record({ name = "extra", id = "9", parent = "0" })
local records = g.prefab.edit({ what = "join", prefab = g.prefab.empty({}), children = { extra } })
local joined = { records = records }