Jump to content

Prefab Load Start Bug

Recommended Posts

Prefab Load Start Bug


Leadwerks 4.3

CPU: AMD FX™-4100 Quad-Core Processor



VRAM: 2048 MB

Version: 375.39

Platform: GNU/Linux Debian Jessie x86_64


Bug: When loading a prefab, the Start function does not fully work. It seems that variables are loaded, but other functions fail to operate. IE SetPosition()


Below are some images displaying the different models and a prefab in the Leadwerks editor:


Models and with scripts attached:












The following images show the prefab and models running in Leadwerks:







Share this post

Link to post

Here are two rough scripts that have were used to show this bug, however there are many other instances of this issue.



function Script:Start()

function Script:UpdateWorld()
       local pitlightmove = Math:Curve(self.fluctuation,self.smoothedfluctuation,5/Time:GetSpeed()*110)



Script.Candle =  "" --entity "Candle"
local candle = "Candle_0"

function Script:Start()
   local pos = self.Candle:GetPosition(true)
   local name = self.Candle:GetKeyValue("name")

   local Flame = Prefab:Load("Prefabs/Effects/CandleLight.pfb")
   if name == candle..1 then
         i = .08
   elseif name == candle..2 or name == candle..3 then
         i = .11
   elseif name == candle..4 then
         i = .15
   elseif name == candle..5 then
         i = .18

   Flame:SetPosition(pos.x,pos.y+i, pos.z)
   local child = Flame:FindChild("Light")


The prefab was created using the model script sample, however once Leadwerks loads the map, the prefab does not set the position. The actual design/setup of the model works as expected.

Share this post

Link to post

The only time I see this is when I load the chandelier prefab via code. If the chandelier prefab is in an editor scene, then it loads everything fine. Is this what you are doing?


Edit-- I went through and fixed the scale on all the candles, candlesticks holders, and the chandelier by opening them in the Model Editor and using Tools>Collapse to set the inherent scale to (1,1,1). Then I rebuilt my chandelier with the candlesticks and added a slightly modified version of the 'LoadCandleFlame.lua' script that makes the flame a child of its candle. Also, my flame is a scaled sprite prefab of the firepit fire and point lights so i had to change slightly the Y positioning of the Flame in the script. Now whether I load the chandelier via the map or load it via code, it loads, runs the scripts, and positions the candles' flames properly.


'LoadCandleFlame.lua' was modified so that it only needed to be attached to the chandelier model itself. Also, note that I didn't use the 'Candle_02.mdl' as its origin was offcenter from the model after fixing the scale.

function Script:Start()

local candle = "Candle_0"

local numberofkids = self.entity:CountChildren()

for j = 0, numberofkids - 1 do

local y = 0

local child = self.entity:GetChild(j)

local pos = child:GetPosition(true)

local name = child:GetKeyValue("name")

local Flame = Prefab:Load("Prefabs/Props/CandleLight.pfb")


if name == candle..1 then

y = .16

elseif name == candle..3 then

y = .19

elseif name == candle..4 then

y = .23

elseif name == candle..5 then

y = .26


Flame:SetPosition(pos.x,pos.y+y, pos.z, true)






Granted all of this could be just turned into one prefab instead of building onto each other...

  • Upvote 1

Share this post

Link to post

Thank-you for all your help. smile.png


macklebee's solution worked very well. Even though,when applied on my rig, the model did not need to have its scale fixed, however the CandleLight.pfb did need to be altered. The flame heights did need adjusting.


Prior to this solution, I would simple load the prefab into the scene and "break" its prefab status, in order to have it work as the original. This would not help in a code loading scenario. Loading the script from the actual model is a much cleaner approach too.



The child.script:Start() line in the original posted script was a last ditch effort to force the prefab to run Start, which was fruitless. wacko.png


So, I suppose my question is: why does this occur?

Share this post

Link to post

I try to not parent anything that doesn't have the scales set up correctly to (1,1,1). It seems there is always something that is going to cause issues with rotation or positioning if you have multiple things scaled especially if you are setting the rotation/position to local space.


As far as child scripts, I just keep in mind that its parent and its parent's parent - all the way to the base parent, must have a script. So far that approach has worked for me.


But in attempt to make this even easier and to avoid any scaled positioning/rotational child issues, this whole assembly could have been one prefab without the need to load another prefab onto it. But I understand your reasoning for it, since you are going to use the same candle flame effect on other items other than the chandelier.

  • Upvote 2

Share this post

Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...