Rick Posted July 20, 2013 Share Posted July 20, 2013 I create a prefab on MouseHit(). The csg that makes up the prefab has a script attached to it, which has a type property exposed: Script.Type = ""--string In the prefab I give this value like, say, "test" and saved that into the prefab so each time I dynamically create this prefab in code it has this value "test" for type. I place a breakpoint inside Script:Start() and I notice when I hit the mouse to create the prefab Script:Start() of the script attached to the prefab is fired twice! Insie Script:Start() I set the key value to the type like: self.entity:SetKeyValue("type", self.Type). The first time it enters into Start() it has the "test" value for self.Type. However, the second time it enters Start() self.Type is empty (""). Why would creating a prefab cause its attached script to fire twice, and the second time not having the saved values for exposed properties of the prefab? Would someone test this themselves to see if I'm crazy or not? Quote Link to comment Share on other sites More sharing options...
Josh Posted July 20, 2013 Share Posted July 20, 2013 Prefabs work by loading a default copy of the entity in the background, and then returning a copy each time that prefab is loaded. You can load the same prefab ten times, and it will just make copies of the original, rather than reloading it from the hard drive. When all copies of the prefab are deleted, the original in the background will be deleted automatically. I don't know why the key would not be set, though, because the entity copy routine copies the keys map. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Rick Posted July 20, 2013 Author Share Posted July 20, 2013 I'd say script properties aren't being copied. If I place the prefab in my scene and run it and break at Script:Start() I see what you are talking about where it loads twice, but Script.Type is empty on the second load. Sounds like a bug. Dangit It's not the entity key's (ie SetKeyValue()/GetKeyValue()) that is the issue, it's the script properties that is the issue. I use the script properties to set the entity keys, but on the 2nd load those script properties are the defaults, in my case empty string, instead of the values of the prefab. For now I think I can just make 2 separate scripts that are more specific to the type. Was just trying to have a more generic script. Quote 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.