Jump to content

Recommended Posts

Prefab Load Start Bug

 

Leadwerks 4.3

CPU: AMD FX™-4100 Quad-Core Processor

RAM: 8GB

GRAPHICS: NVIDIA GeForce GTX 750 Ti

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:

 

post-16788-0-72621600-1493987474_thumb.png

 

post-16788-0-43941000-1493987488_thumb.png

 

 

Prefab:

 

post-16788-0-07230600-1493987499_thumb.png

 

 

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

 

post-16788-0-48300800-1493987510_thumb.png

 

post-16788-0-51655900-1493987519_thumb.png

 

post-16788-0-14120900-1493987530_thumb.png

SpEcIeS

Link to comment
Share on other sites

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

 

CandleFlicker.lua:

function Script:Start()
       self.fluctuation=1.0
    self.smoothedfluctuation=1.0
end

function Script:UpdateWorld()
       self.fluctuation=self.fluctuation+math.random(-100,100)/50.0*Time:GetSpeed()
    self.fluctuation=math.min(1.8,self.fluctuation)
    self.fluctuation=math.max(0.2,self.fluctuation)
       local pitlightmove = Math:Curve(self.fluctuation,self.smoothedfluctuation,5/Time:GetSpeed()*110)
    self.smoothedfluctuation=Math:Curve(self.fluctuation,self.smoothedfluctuation,5.0/Time:GetSpeed())
       self.entity:SetColor(1.0*self.smoothedfluctuation,0.6*self.smoothedfluctuation,0.25*self.smoothedfluctuation,1,0)
end

 

LoadCandleFlame.lua

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
   end

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

 

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.

SpEcIeS

Link to comment
Share on other sites

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")

Flame:SetParent(child)

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

end

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

end

end

 

post-14-0-67046100-1494112084_thumb.jpg

 

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

  • Upvote 1

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

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?

SpEcIeS

Link to comment
Share on other sites

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

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
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.

 Share

×
×
  • Create New...