๐Ÿงฉ Parent & Child Hierarchy

The hierarchy system allows an object to act as a parent of others, so when the parent moves or rotates, all its children follow it. This is extremely useful for UI organization, modular objects, or building more complex structures such as a player with a weapon, a spaceship with lights, or an enemy with multiple components.

Besides the basic setParent() and getParent() functions, the engine provides additional utilities for hierarchical management: getAllChildren(), detachAllChildren() and destroyAllChildren().

๐Ÿ› ๏ธ Using the Hierarchy from the Editor

The easiest and most visual way to create parentโ€“child relationships is by using the Hierarchy panel inside the Editor.

๐Ÿ“Œ Creating a Child by Dragging

โœ” This is equivalent to calling setParent(child, parent) in code.
โœ” The engine automatically calculates localX and localY to keep visual alignment.

โŒ Detaching a Child (Removing the Parent)

When an object has a parent, the Inspector shows the parent's name with a small X icon next to it.

โœ” This action is equivalent to calling setParent(obj, null) in code.
โœ” The object keeps its absolute world position.

๐Ÿ“˜ 1. setParent(child, parent)

Assigns a child object to a parent. Automatically calculates localX, localY and localRotation to preserve its current visual position and orientation.

Syntax

setParent(child, parent)

Parameters

Example

// Make the arm a child of the body
const arm = getObjectByName("Arm");
const body = getObjectByName("Body");
setParent(arm, body);

// Detach the arm
setParent(arm, null);
- An object cannot be parented to itself or its descendants.
- Children inherit movement, rotation and scaling.
- Passing null removes parenting and inheritance.

๐Ÿ“— 2. getParent(child)

Returns the parent of an object, or null if none exists.

const parent = getParent(child);

Example

function Update(o, dt) {
  const parent = getParent(o);
  if (parent) {
    console.log(o.name + " belongs to " + parent.name);
  }
}

๐Ÿ“™ 3. getAllChildren(obj, recursive)

Returns all direct children, or if recursive is true, all descendants in the hierarchy.

const all = getAllChildren("Parent", true);

๐Ÿ“’ 4. detachAllChildren(obj)

Detaches all children of an object (same as setParent(child, null) for each).

detachAllChildren("EnemyBoss");

๐Ÿ“• 5. destroyAllChildren(obj)

Removes all children and descendants recursively.

destroyAllChildren("EnemyBoss");

๐Ÿ“ Rotation & Position Inheritance

When a parent rotates, all its children rotate around the parentโ€™s center, keeping their relative angle and distance.

Useful Functions

Example

const player = getObjectByName("Player");
const weapon = getObjectByName("Weapon");
setParent(weapon, player);
rotateObject(player, 30);
- Rotations are stored in degrees.
- localRotation is calculated when parenting.
- Children rotate around the parentโ€™s center.