Rick Posted March 18, 2013 Share Posted March 18, 2013 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 Quote Link to comment Share on other sites More sharing options...
Chris Vossen Posted March 20, 2013 Share Posted March 20, 2013 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? Quote Link to comment Share on other sites More sharing options...
Rick Posted March 20, 2013 Author Share Posted March 20, 2013 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. Quote Link to comment Share on other sites More sharing options...
YouGroove Posted March 21, 2013 Share Posted March 21, 2013 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 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. Quote Stop toying and make games Link to comment Share on other sites More sharing options...
Rick Posted March 21, 2013 Author Share Posted March 21, 2013 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. Quote Link to comment Share on other sites More sharing options...
YouGroove Posted March 21, 2013 Share Posted March 21, 2013 Well only trying it in a some game needing to create entities at run time we 'll show if it is fast or not ? The Prefab question remains. Quote Stop toying and make games Link to comment Share on other sites More sharing options...
xtreampb Posted March 24, 2013 Share Posted March 24, 2013 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. Quote 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! Link to comment Share on other sites More sharing options...
Recommended Posts
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.