Phodex Games Posted July 16, 2018 Share Posted July 16, 2018 Ever since I had struggle with the prefab system. I wonder if I am doing something wrong, if it just has bugs or if it just lacks documentation... Here a few examples of what I have encountered so far: 1. I just set up a test scene to analyize the prefab behavior. So I attached a few csg boxes, a light and a particle emitter to another csg box. When I save the parent box as prefab so far everything works as expected, but then when I change the child boxes physics to prop and set a mass for them, thing are getting weird. If I am in the editor and drag the prefab from the asset window into the scene, everything still works as expected, but if I load the prefab ingame by script, the child boxes just don't appear. 2. Sometimes pivots parented to an Prefab seem to not save position. They randomly have an offset, although I set their local position to 0,0,0 3. Especially particle emitters which are prefabs have a weird behavior. They begin to emit diffrently (they burst instead of emitting smoothly), although I think this only happens in the editor viewport and not when you start your game 4. I also encountered that my code did not work as expected anymore, when using them on prefabs. There seem to be some reference error. I just worked on destroyable objects and when I place them as normal objects not beeing prefabed everything works fine, but if I save them as prefab and place them in the scene, everything is messed up. The destroyed version of the object always spawns on the position of the first placed prefab and the old, intact version does not get removed. I guess I have a clue how to work around this, but the weird thing is it works fine when the object is no prefab. So the point is I just don't know where the error is, it are these small things which make me struggle working with Leadwerks sometimes, when it does not work as expected and you can't really find the error. Maybe I am just missing some information on how to use prefabs and how to not use... Thanks for any helpful advice 1 Quote Link to comment Share on other sites More sharing options...
reepblue Posted July 16, 2018 Share Posted July 16, 2018 Be careful using prefabs with CSG as they can cause unusual effects. Prefabs do not really want to work with complex situations. They are mostly useful for spawning models with a script pre-assigned to them. This would be something I would just assign the object with a script or actor and create the objects I need in the code. I usually never use prefabs due to situations like this, but I'm sure others adore them. ? 1 Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
Phodex Games Posted July 16, 2018 Author Share Posted July 16, 2018 1 hour ago, reepblue said: they can cause unusual effects Well that exactly the problem ^^. I guess the prefab system need to be worked on in the future. It's a little sad, because if I could rely on them, they would be a great addition to my workflow. 1 hour ago, reepblue said: just assign the object with a script or actor and create the objects I need in the code Yeah thanks for the input, I guess I have to come up with my own system. For what ever reason I actually enjoy using my brain, solving such problems, instead of just having the feature working fine haha Quote Link to comment Share on other sites More sharing options...
Phodex Games Posted July 16, 2018 Author Share Posted July 16, 2018 Actually after some research if found the error why the boxes "disappear" when setting physics to them. They do actually load, I just did not see them as they were in the ground. For whatever reason their position gets distorted. This seems to happen when you set/change the mass setting of an entity in the Start function, which does seem to happen when loading the prefab. But if I set the mass manually on the first update call it works, but the entity does not collide with others, although it has mass and prop physics on it. This however can be solved by setting the whole physics settings when the first update function is called. Like this: function Script:UpdateWorld() if self.awake ~= true then self.awake = true self.entity:SetPhysicsMode(Entity.RigidBodyPhysics) self.entity:SetCollisionType(Collision.Prop) self.entity:SetMass(10) end end Maybe this can help fixing the bug. I guess that is one of the reason for the weird behavior with my prefabed destructible objects. Quote Link to comment Share on other sites More sharing options...
reepblue Posted July 16, 2018 Share Posted July 16, 2018 Some entities also act weird when they are a child to something. Since you need to parent things to save as one object, you can try breaking the prefab up buy unparenting all the root entity's children on Start. I recall doing something like that before.. Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! 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.