Jump to content

Recommended Posts

Posted

I'm creating a PrefabFactory script where you fill out a property of the prefab file and destination. I'm testing with the goblin and I'm able to create a goblin but it just sits there. If I pass 0 as the 2nd param to Prefab:Load() I get an error because the scripts don't seem to get loaded. If I pass a 1, like below, I don't get the error, the goblin model is where it's supposed to be, but it's not animating or doing anything so it doesn't seem like the scripts are really getting executed. Not sure if this is a bug or what?

 

 

The script source is:

 


Script.prefabFile = ""--string "Prefab File"
Script.destination = nil--entity "Destination"

function Script:Start()
end

function Script:CreatePrefab()--in
self.entity = Prefab:Load(self.prefabFile, 1)

self.entity:SetPosition(self.destination:GetPosition())
end

Posted

I'm a little confused as to the exact nature of the prefab factory. Are you trying to input a prefab name and destination and then have a function that when called will load a prefab at that destination?

Posted

Correct. Think of it being used in a wave manager for a tower defense game. Let's say every 2 seconds I want to create a new Goblin to rush the tower! You would use this that creates that goblin prefab isntance and all scripts attached.

 

Prefabs are great for making manually in the editor, but it's more powerful if I can make instances of these prefabs via code.

 

 

[EDIT]

To give an example, in the tweaks I was doing to DA, when you got into the room with the switch, after you hit the switch I created a prefab instance of a goblin as a surprise attack. The goblin, however just sat there not even doing the idle animation. It was there frozen.

Posted

More simple , the function to load a prefab by code are you sure it will load all stuff not only the model ?

And where it is specified loading it will run some attached script ?

 

Anyway, for optimisation :

Creating/deleting objects IS SLOW smile.png

 

For the tower defense the best is you to create a pool of objects at game start (a pool of maximum towers or minimum you would need).

Place them at (0,-500,0), make them invisible , no collision.

And when you need one on the game, just move it where you need it by changing it's position , and make it collidable and visible.

 

*************

 

But yes be able to load a prefab or object and load some attached script and be able to run the script would be necessary.

Stop toying and make games

Posted

Creating objects isn't slow when they are instanced, which I believe LE does. So as long as creating 1 object of each prefab creating other objects of the same prefab should be fast because of instancing. Creating and deleting objects at run-time happens all the time in games.

Posted

YouGrove, my demo, Castle Defense, everything is created at run time. the wall is created and everytime a sone is thrown, the stone and all the smaller borken pieces are created on the spot. It only starts to slow down b/c i don't clean up all the broken pieces laying on the ground.

bool Life()
{
 while(death=false)
 {
   if(death==true)
   return death;
 }
}

 

I have found the secret to infinite life

 

Did I help you out? Like my post!

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.

×
×
  • Create New...