Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commite8beb5604c

README.md

prefab.add_component (procNode)

Add a component (type and data) to a prefab's root entity. Each call appends one, so calling twice with the same type leaves the root carrying two of them. Use it to give a prefab's root its behaviour: a light, a collider, a script component.

The component is written into the root record as { type, data }, and data is handed to component.add when the prefab is spawned. Built from prefab.edit (what = "add_component").

Inputs

  • prefab (Prefab). The component lands on the prefab's root entity, the first record, whatever entities were added to it after that.
  • type (String, default ""). The component type added to the root entity. Required: an empty type is an error.
  • data (Record, optional). The component's fields, carried into the record as they are. Absent, the record holds an empty data table and the component takes its schema's own defaults.

Outputs

  • prefab (Prefab). A new prefab value, { records = { ... } }; the prefab wired in keeps the records it had.
local lamp = g.prefab.add_component({ prefab = g.prefab.empty({ name = "lamp" }), type = "Light", data = { intensity = 3 } })