Jump to content

Prefabs not working correctly


beo6
 Share

Recommended Posts

When i use

local building = Prefab:Load("Prefabs/Buildings/"..pfbfile)

 

in my script, the Start function is not called and trying to call it manually with

building.script:Start() ends with an exception.

 

 

If i place it in the Map with the editor, the placed entity calls its start script, however

GetKeyValue("name") returns nothing.

 

When the Prefab is placed with the editor and i load another prefab with the script the loaded prefab calls its Start function and returns the correct GetKeyValue("name")

 

 

This issue might be related:

http://www.leadwerks.com/werkspace/topic/13048-foreachentityinaabbdo-to-find-entities/

 

 

//Edited thread title as there is even a small bug when placing it with the editor.

Edited by beo6
  • Upvote 1
Link to comment
Share on other sites

  • 2 weeks later...

Yes. i know that Thread, i thought it is obvious what the issue is. Sorry about that.

 

Have now created a project where i reproduced the issues. Hope that helps to fix them.

 

https://cloud.software-sl.de/index.php/s/TjuqtGZ3gyWorUC

 

Press the Space key to call the Prefab:Load function.

the loading script part is in the gamecontroller.lua script.

 

There are two maps.

"callingStartFunctionButEditorPlacedDoesNotReturnName.map"

Where the prefab is already placed in the editor. There the prefab that was placed with the editor does not return the Name but the Start function is called. The by script loaded prefabs do return the name and Start is called.

 

"notCallingStartFunctions.map"

this one is without a placed prefab in the map.

There the loaded prefabs do never call Start.

 

It seems that the Start function is not called when the first load has Prefab.NoStartCall as parameter.

Then the prefabs loaded after that do still not call the Start Script even if that parameter is missing or i explicitly set the parameter Map.LoadScripts

  • Upvote 1
Link to comment
Share on other sites

  • 2 weeks later...

Thanks.

 

Using

Prefab:Load("Prefabs/myprefab.pfb", Map.LoadScripts+Prefab.NoStartCall)

 

seems to work.

 

But it feels a bit odd since calling only

Prefab:Load("Prefabs/myprefab.pfb")

 

for the first time does load the script. So it is not really clear that Prefab.NoStartCall does completely prevent loading the script and not only just prevents calling the Start function.

 

 

//Edit: what about that prefabs placed by the editor do not return their entity name with

self.entity:GetKeyValue("name") ?

Edited by beo6
Link to comment
Share on other sites

  • 3 weeks later...
  • 10 months later...
  • 3 weeks later...

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