Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Why do trigger events require at least one non-static physics body?

Discussion in 'Physics for ECS' started by varnon, Apr 23, 2021.

  1. varnon


    Jan 14, 2017
    I had some issues with trigger events recently because I completely forgot that one dynamic or kinematic physics body was required. I'm coding my own kinematic controller for the moment, so I wasn't in need of the physics simulation. Took me a bit to figure out, and I do seem to recall seeing it in documentation somewhere. But I'm curious as to the purpose of this. Why is a non-static physics body required? It would seem like checking for collider overlaps would be sufficient without a physics body. Its been a while, but I seem to recall a similar requirement for gameobject colliders and ridged bodies.
    BeerCanAI likes this.
  2. petarmHavok


    Nov 20, 2018
    Yeah, it's not due to the fact that we need a body, it's an optimization thing. Let me try to explain.

    Trigger bodies are no different than any other body. They perform broad phase sweeps, respond to queries (if you want them to), have collision detection, prepare for solving, even get solved. But when they get solved, instead of applying impulse, they check if they would apply the impulse, and if so, they fire an event instead. In the end, they get integrated just as any other body.

    So, the entire pipeline is almost identical (except from the small diff in solver part). Now imagine if all static bodies would have to go through the same thing (and they would) just to fire this event. Physics engine cost would be much bigger. And we filter out static-static pairs instantly, at the very first step, we don't even detect them. So there is no interaction of static bodies in the engine, thus no triggers.

    If you're wondering how we filter them out efficiently, we actually have 2 spatial trees - static bodies one and dynamic bodies one. When we overlap them, we overlap static vs dynamic and dynamic vs dynamic. So it's literally impossible to get a static-static pair in your step.
    CrazyD0G, BeerCanAI and steveeHavok like this.