Jump to content

Something wrong with Prefabs?


Phodex Games
 Share

Recommended Posts

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.

1435188358_Shotone.PNG.e0d94b0c8c87250744ec5150f5a38dc8.PNG

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 :)

  • Upvote 1
Link to comment
Share on other sites

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. ?

  • Thanks 1

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

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 :D

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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..

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

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...