Load
This function loads a prefab from a .pfb prefab file. When the prefab is loaded, any entities in the hierarchy with a script attached to them will have the Start() function called.
Syntax
- Entity Load(string path, number flags=Map.LoadScripts)
Parameters
- path: the file to load the prefab from.
- flags: asset load flags. In addition to the standard Asset and Map load flags, this can also include the value Prefab::NoStartCall, which will prevent execution of the "Start" function. Note that the flags parameter must include Map::LoadScripts if you want the prefab script to be loaded.
Returns
Returns an entity if the prefab is successfully loaded, otherwise NULL is returned.
Example
--Create a window
window = Window:Create()
context = Context:Create(window)
world = World:Create()
local camera = Camera:Create()
camera:Move(0,0,-6)
local light = DirectionalLight:Create()
light:SetRotation(35,35,0)
--Create the ground
local ground = Model:Box(10,1,10)
ground:SetPosition(0,-0.5,0)
ground:SetColor(0.0,1.0,0.0)
--Create a shape
local shape = Shape:Box(0,0,0, 0,0,0, 10,1,10)
ground:SetShape(shape)
shape:Release()
--Load a prefab
Prefab:Load("Prefabs/Effects/smoke.pfb")
while true do
if window:Closed() or window:KeyHit(Key.Escape) then return false end
Time:Update()
world:Update()
world:Render()
context:Sync()
end