natiny.entity.set_parent

Lua
natiny.entity.set_parent(child, parent)

Sets the parent of a node, creating a parent-child hierarchy. The child node's transform becomes relative to its parent.

Parameters

Name Type Description
child number Child Entity handle
parent number Parent entity handle, or 0 to detach

Example

Lua
natiny.entity.set_parent(hand, arm)

Notes

  • Reparenting preserves the child's local position, rotation and scale; its world transform therefore changes immediately relative to the new parent.
  • Pass 0 as parent to detach the child. Its local transform is preserved and becomes its world transform.
  • Detaching is also what spares a child from its parent's destroy: every destroy that owns an entity takes the whole subtree under it with it.
  • This is how a visual follows something that is not one: parent a model to a rigid body, or a sound source to a model, and the child needs no attention of its own afterwards. A mesh cannot be parented
  • it is geometry, with no place in the scene.
  • When the parent should be a point rather than a thing - an axle, a mount, a muzzle - make it a pivot: a node with a transform and nothing else.
  • natiny.entity.get_parent reads the parent back, and answers 0 for a node at the root.