- Home /
why are child colliders sometimes ignored?
i have noticed in a number of my projects that when i instantiate an object with a rigidbody and then give it a child with a collider the physics engine will sometimes ignore that collider even tho it is active. if i toggle the collider off and then on in the editor it magically starts working or if i cast a ray onto it in script it starts working. so what is causing the physics engine to ignore the collider and is there a better work around than casting rays on all of my instantiated objects to force unity to recognize that it exists?
EDIT: THIS BUG HAS BEEN FIXED IN UNITY 5+ AND IS NO LONGER A PROBLEM.
No it's not been fixed, it's as frustrating as ever!
Answer by Owen-Reynolds · Oct 19, 2014 at 03:26 AM
I'm pretty sure there's a few situations where changing an object in code will confuse physics. Seems like you have to "kick" it to get it to recalc values. The simplest solution is to do things the "Unity way" if you can -- like Instantiate parent+child all at once (if you have 4 configurations of parents/kids, make a prefab for each.)
One thing I think I've had success with is what you describe doing by hand. In code, set the object inactive then active (or kinematic/non?)
unfortunately i can not use prefabs for my project. i am creating a voxel based game where the player creates the objects block by block. the problem is sometimes the blocks they add are ignored by physics and sometimes they aren't. and interestingly when i go thru and toggle them on and off it fixes the ones that are broken but then breaks the ones that were working.
toggling the kinematic property dose nothing. toggling active on the parent(rigidbody) object works but then all connected joints go nuts.
toggling the collision detection mode works but if i go from discrete to continuous and then back to discrete collisions work when the object is moving but as soon as you stop they fall thru each other. going continuous-discrete-continuous works great but then im stuck using continuous mode which i dont need and it causes lag
Joints have their own set of issues. When you make one, I think, the current position is always taken to be "at rest." In other words, there's no way to properly add a hinge to an open door (well, maybe by playing with the limits: -45/+45 becomes -90/0. $$anonymous$$aybe.)
So I wonder if the toggle active/inactive is resetting joint "at rests."
I've never seen a decent guide to Unity joints, esp. dynamic joints.
If you have problems with adding a joint at runtime, try adding a joint component in FixedUpdate frame and use next and/or previous FixedUpdate frame to position the gameobjects you want add the joint.
This is because, when you add a joint component on a gameobject the joint component uses the current position of the gameobject/gameobjects for initialization.
titulus: Gah!! Is this the "takes 1 physics step to see new location" issue? So if, in one update, you move an object then add a joint, it will connect based on the old position?
Disclaimer: I have never experienced anything like this.
Answer by sweatyrat · Jan 27, 2015 at 07:15 PM
After a long time of frustration and experimentation i have had some success by simply setting the rigidbody's transform equal to null after all the colliders have been attached. that seems to be the only way to compleatly reset the collision calculations.