Using a concave mesh as a trigger?

How can I use a shape like this as a trigger?

I want it to be a trigger to detect if the player is standing on it, is there a way of doing this? If I made it a concave trigger, the player will set the trigger off on almost anything inside there and if I were to somehow break it up, I’d have to surely have hundreds of trigger test scripts on each piece?

I don’t think PhysX (Unity’s physics subsystem) supports concave triggers. You generally have to break it up into multiple convex triggers. Luckily you don’t have to have multiple scripts. As long as the convex colliders are all on child objects of your object with a script that listens for the triggers, any of the colliders will trigger a call OnTriggerEnter on the one script. Test it out with a simple example to see!

I actually did but I couldn’t figure out how to do it, does the trigger script go on the parent? And if so, should there be a mesh collider on that? I tried various things but the only thing that worked was putting the script on each part.

Also, how on earth do I break something like this up into individual pieces that are accurate?

This works for me:

Parent GameObject:
Components: Rigidbody, MonoBehaviour with OnTriggerEnter

  • Child GameObjects:
    Components: Trigger collider

Then OnTriggerEnter will be called if a trigger of any child is entered.

Not sure about that haha. How did you generate the shape in the first place?

Thanks, I’ll try that!

Probuilder!

So Probuilder has a button called “Set Trigger” which basically turns the currently selected object into a trigger-only version of itself. What happens if you duplicate your complicated thingy and hit “Set Trigger” on it? Does it just create one big bad convex mesh collider?

Weirdly enough it seemed to just add a script and turn on the convex/trigger checkboxes (and wipe out my material). I’m a little confused tbh, I don’t claim to understand collision engines, but surely the fact the player could walk around and collide perfectly on this concave mesh, or I could put a rigidbody on it, cast a ray from the player and always hit it concave mesh means it’s possible to determine where the precise edge of any mesh is. But I don’t understand why a trigger can’t work like this?