0
\$\begingroup\$

I have a number of GameObjects with 2 child GameObjects:

  • Sprite
  • Words

There is a a BoxCollider2D on both the Sprite child and the Words child. The parent has a Composite Collider 2D on it, which uses those BoxColliders. It automatically calculates perfect polygon colliders, and is working great.

My GameObjects can sometimes nest. You can see an example in the attached pictures, where a Snake GameObject has a Zebra GameObject nesting under it.

enter image description here

The Composite Collider 2d for the Snake is not picking up on the Box colliders for the grandchildren nodes (Zebra/Sprite and Zebra/Words). I am guessing that's because a Composite Collider will only combine colliders from Box Collider 2D or Polygon Collider 2D, and not from another Composite Collider.

Is it possible to have a Composite Collider (or some other collider aggregator) pick up the colliders for not only child nodes but also grandchildren nodes? And great grandchildren, etc. My whole data model currently uses nesting of GameObjects, so it'd be great to be able to continue with that while also taking advantage of a Composite Collider. Thanks!

\$\endgroup\$
0

1 Answer 1

2
\$\begingroup\$

Is it possible to have a Composite Collider (or some other collider aggregator) pick up the colliders for not only child nodes but also grandchildren nodes?

Yes, the CompositeCollider2D component will pick up all children and grandchildren (and all others down the hierarchy) with Box Collider 2D or Polygon Collider 2D. The problem in your setup is that Zebra has its own Composite Collider and a Rigidbody 2D and it's combining its own children into a single collider.

My whole data model currently uses nesting of GameObjects, so it'd be great to be able to continue with that while also taking advantage of a Composite Collider.

Would you be able to disable remove a Composite Collider and Rigidbody2D on nested objects? That should fix your issue.

\$\endgroup\$
2
  • \$\begingroup\$ << The problem in your setup is that Zebra has its own Composite Collider and a Rigidbody 2D and it's combining its own children into a single collider. >> Ah I had tried removing the Composite Collider for the Zebra, and that hadn't worked... but hadn't tried removing the Rigidbody 2D. Did that and it worked perfectly - THANK YOU!! \$\endgroup\$
    – kanamekun
    Commented May 28, 2022 at 15:38
  • \$\begingroup\$ For the future, if you check the Collider 2D in the inspector it contains a helpbox that gives you information if the compositing is broken e.g., "This collider will not function with a composite ..." \$\endgroup\$
    – Marunia
    Commented May 28, 2022 at 15:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .