FindChild

This function performs a recursive search and returns the first child entity it finds with the specified name.

Syntax

Parameters

Returns

Returns the first child entity found with the specified name. If no child is found, NULL will be returned.

Example

--Create a window
window = Window:Create()
context = Context:Create(window)

world = World:Create()

local camera = Camera:Create()
camera:SetRotation(35,0,0)
camera:Move(0,0,-3)

local light = DirectionalLight:Create()
light:SetRotation(35,35,0)

--Load a model
local entity = Model:Box()

local child = Model:Box(1,1,1,entity)
child:SetColor(1.0,0.0,0.0)
child:SetPosition(2,-2,0)
child:SetKeyValue("name","MyBox1")

child = Model:Box(1,1,1,entity)
child:SetColor(0.0,1.0,0.0)
child:SetPosition(-2,-2,0)
child:SetKeyValue("name","MyBox2")

while true do
if window:Closed() or window:KeyHit(Key.Escape) then return false end
Time:Update()
world:Update()
world:Render()

local child = entity:FindChild("MyBox2")

context:SetBlendMode(Blend.Alpha)
context:DrawText("Child position: "..child:GetPosition(true):ToString(),2,2);

context:Sync()
end