Jump to content

Load prefab, pass entity


drarem
 Share

Recommended Posts

I would like to load a prefab and want to pass the player entity to the loaded prefab's attached script to initialize it its the start() function. How should I handle it?

 

Thanks.

 

Example:

(player.lua)

self.player.entity:SetPosition(0,0,0)

local test = Prefab:Load("Prefabs/test/test.pfb")

 

 

For test.pfb attached script:

(test.lua)

function Script:Start()

self.startpos = ??? (somehow pass or get player entity position)

self.endpos = self.entity:GetPosition()

end

Link to comment
Share on other sites

i guess i would do it like this:

 

Example:
(player.lua)
self.player.entity:SetPosition(0,0,0)
local test = Prefab:Load("Prefabs/test/test.pfb", Prefab.NoStartCall) --prevent calling start on load
if test.script~=nil then
 test.script.startpos = self.entity:GetPosition() --send position here
 test.script:Start() --call start here
end

For test.pfb attached script:
(test.lua)
function Script:Start()
  self.startpos = ???  (somehow pass or get player entity position)
  self.endpos = self.entity:GetPosition()
end

  • Upvote 1
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...