Unity Bug? Instantiating box collider during runtime

Here’s my current dilemma. It appears to be pointing towards a Unity bug…though not exactly sure.

  1. I have a prefab of a GameObject which contains:
  • Rigidbody (UseGravity: ON)
  • Box collider (Trigger: ON)
  1. In my scene, I simply have ground plane with:
  • Box collider (Trigger: OFF)
  1. My goal is to be able to dynamically instantiate this prefab from #1, toss it in the air and have it land via gravity on the ground plane.

  2. With the current set up above, if I instantiate #1 in the air, it will drop down and right through the ground plane. Understandable because Trigger is ON in #1.

  3. So in order to maintain the Trigger:ON status in #1 and still be able to collide with the ground plane, I decided that during the dynamic instantiation of step #4, I would also create a new child GameObject with a Box collider (Trigger: OFF). I will then parent this child collider object to the object at #1.

  4. This produces the following object in runtime memory:
    GameObject from #1 (Trigger:OFF)
    |- GameObject (Child) from #5 (Trigger:ON)

  5. This dual collider setup actually WORKS if I did not generate and parent the new child collider GameObject in #5 DYNAMICALLY during runtime. However, I would like to perform this step in runtime. Unfortunately, doing so in runtime results in the object falling right through the ground plane, as if the collider did not take effect. I also double-checked the dynamically generated objects in the Editor by pausing the game, to verify that the child object is created and parented properly. Still no clue.

Anyone ever run into this issue? :roll:

Hello!

Just a thought.
Have you tried using a joint between them, instead of parenting ?

Nope, havent tried using joints. Thanks for the suggestion, maybe I’ll give that a try. :slight_smile:

But it’s still perplexing to me why parenting didn’t work when coupled at runtime… :roll: