Wings Engine

Fetching Parent and Child Nodes of an Element

Currently, secondary development provides getParent and getChildren methods to retrieve the parent and child nodes of an element, allowing us to get the complete structure of the layer list. For more details, refer to the API documentation.:Element class

This interface is mainly used in 3D secondary development, but it can also be applied in 2D. Let’s take a look at how to use this interface.

First, we create a sample 3D scene in the Wings Engine:

Attach the secondary development code to the model element:

1
2
3
4
5
6
7
8
9
10
export class SampleExtension {
async init() {
const children = this.element.getChildren();
for (let i = 0; i < children.length; i++) {
console.log(children[i].name);
}
const parent = this.element.getParent();
console.log("parent", parent.name);
}
}

After reloading the code, we can see that the child elements and parent elements of the current element are printed.