Handling Nodes

getChild(parentId, child)

Returns the transform id (int) of child named child (string), which is a child to the transform of id parentId (int, transform id). This can also be used to find the a child of a children by separating the layers using slashes (/). Therefore, the syntax is comparable to Transform.Find.

Additionally, if child starts with !, it will reference to the parent of parentId. Also, it is possible to specify the child index instead of the name (so that the syntax becomes similar to getChildAt). In that case, the names have to be separated using > instead of /. Also, it is not allowed to use both reference by name and reference by index within one string.

function getChild(parentId, child) 

getChildAt(parentId, n)

Returns the n+1th child of the parent (specified by its transform id parentId). Similar to getChild, this function will return the desired child's transform id (int).

function getChildAt(parentId, n) 

getParent(objectId)

Returns the transform id (int) of the object's parent. The object is indexed using its transform id (int) objectId. Returns 0 if the object is not attached to any parent but to the world's root node.

function getParent(objectId) 

setParent(objectId, parentId, worldPosStays)

Makes the object with objectId (transform id) be a child of parentId (transform id). Depending on worldPosStays (optional bool),

  • the object's world position will stay the same (if nil or true)
  • the object's local position will stay the same (if false)
function setParent(objectId, parentId, worldPosStays) 

isChildOf(objectId, parentId)

Returns true if the object with objectId (transform id) is a child of parentId (transform id) and false otherwise.

function isChildOf(objectId, parentId)

getNumOfChildren(objectId)

Returns the number of children the object with objectId (transform id) has. The return value will be an int.

function getNumOfChildren(objectId) 

getSiblingIndex(objectId)

Returns the index of the transform with objectId (transform id) as int. This will call Transform.GetSiblingIndex in C#.

function getSiblingIndex(objectId) 

setAsFirstSibling(objectId)

Makes the object with objectId (transform id) be the first child of its parent. This will call Transform.SetAsFirstSibling in C#.

function setAsFirstSibling(objectId) 

setAsLastSibling(objectId)

Makes the object with objectId (transform id) be the last child of its parent. This will call Transform.SetAsLastSibling in C#.

function setAsLastSibling(objectId) 

getName(objectId)

Returns the name of the object with objectId (transform id). The return value will be a string.

function getName(objectId) 

setName(objectId)

Sets the name of the object with objectId (transform id) to name (string).

function setName(objectId) 

getActive(objectId)

Returns whether the object with objectId (transform id) is active or not (bool).

function getActive(objectId) 

setActive(objectId, isActive)

Sets whether the object with objectId (transform id) is active or not (bool).

function setActive(objectId, isActive) 

getLayer(objectId)

Returns the layer id (int, range 0 to 31) of object with objectId (transform id). This page from the Unity Documentation may be relevant as well.

function getLayer(objectId) 

setLayer(objectId, layer)

Sets the layer of the object with objectId (transform id) to layer (int from 0 to 31). Again, this page from the Unity Documentation may be relevant.

function setLayer(objectId, layer) 

Iterators

Some functions can be called in a for statement (similar to for k, v in pairs(table) do). The functions are explained below.

getChildren(objectId)

This will iterate over all children of the object whose objectId (transform id) is specified. Children's children will not be returned. Inactive objects will be included.

Returns two values, first the object's index (starting with 0, increasing by one per object) and second the object's transform id.

for n, id in getChildren(objectId) do
    -- do something on the object with id, for example call a print:
    print(string.format("child object number %d has id %d", n+1, id));
end;

getActiveChildren(objectId)

Similar to objectId, but this will iterate over active children only.

Returns two values, first the object's index (starting with 0, increasing by one per object) and second the object's transform id. Inactive children will be left out, but the function will still return the correct index.

for n, id in getActiveChildren(objectId) do
    -- do something on the object with id, for example call a print:
    print(string.format("The child object number %d (with transform id %d) is active!", n+1, id));
end;

getChildrenRecursive(objectId)

This is the same as getChildren, except that it will also include children's children.

It will also return two values, but this time the first value will not represent the index but rather the number of the loop iteration, starting with zero. The second return value is again the child's transform id.

Please be careful when calling getChildrenRecursive. This can impose a significant performance burden in case there are many children. For some objects, the total child count may be even larger than thousand objects.

for n, id in getChildrenRecursive(objectId) do
    print(string.format("This is iteration number %d of this loop. This time, the transform id is %d", n+1, id));
end;

All contents of this page may be used for modding use for Winter Resort Simulator only. Any use exceeding this regulation is not permitted.

Copyright (C) HR Innoways, 2020. All Rights Reserved.