Compound Colliders How?

Somehow I don’t get compound (trigger) colliders to work as I would expect:

I’ve got an object appelboom with rigidbody set to kinetic, a script that watches triggers and two child objects (kruin and stam), both child objects have box colliders with isTrigger=true.
I would expect the script in appelboom to be triggered if something crosses the collider in kruin or stam, but it doesn’t. Am I missing something?

Thanks in advance,
Jaap

To demo the problem here a very simple unity project, a ball dropping on a box which has a child object with the (trigger) collider. The box has the script that I hoped would get the message.

From the forums and the docs (although the latter is not really clear on this) what I do is how you make a compound collider (only normally with more than 1 child probably). Don’t want to have a script in every child (for complex compound collider that would give quite a lot of active scripts).

(a completely unrelated question, what do you need to include in a zip when distributing unity source? Only Assets or must Library and Temp be included as well?)

89700–3518–$beingfrustrated_735.zip (509 KB)

Can’t anybody help me? Please, it’s kinda blocking for me and I assume this is something others have tackled before me. Again, thanks in advance.

In case you’re wondering what I’m needing it for is, I’m building a garden game and you can place objects (plants, trees, …) in the garden, besides standard rules like an apple tree needs 3x3 tiles I also want to check if the colliders of the object run into colliders of other objects in the garden. As some trees have quite many colliders I don’t want to have to add a script to every collider. You can see the current state of the project at Ctrl-J - About Ctrl-J mind that the collider stuff is turned off at the moment and it’s very early in development (lots of assets are placeholders from earlier game).

Hi jkreijkamp,

I checked out your project, and the problem is that compound colliders only work for non-trigger colliders. This isn’t made clear by the documentation, so I can see why you tried your approach.

In your situation, the solution is unfortunately to have a script on every trigger in an object. While it might be annoying to attach all these scripts (although using prefabs should make it less annoying), rest assured it will not put any extra strain on Unity, as OnTriggerEnter() is only called when something enters a trigger. There is little or no overhead from having scripts attached to things if their functions do not get called.

Thanks Muriac!

I guess I’ll have the scripts attached automatically by enumerating all kids with colliders. Luckily only the ‘dummy’ instance used for feedback while placing an object needs those scripts, because with the current design they easily have about 30+ colliders each. I need fairly many colliders because they’re also used to measure the distance from the centre of the camera in foto-camera mode, that use DoF. If there’s another way to measure distance to an object on screen without colliders (you can’t read back the Z-buffer, can you?) I would love to hear :wink:

For now, at least, I know what the problem is (it’s not me missing something obvious but just normal, not so well documented, behaviour), so can make a working solution :wink: