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.
  2. Dismiss Notice

Question Find overlapping colliders after instantiation

Discussion in 'Physics' started by stefanob, Jan 19, 2023.

  1. stefanob

    stefanob

    Joined:
    Nov 26, 2012
    Posts:
    64
    Hello,

    I try to use OnTriggerEnter for colliders I instantiate. They don't move, I just want to see if they overlap.
    I searched a lot and tried many things. Moving them a tiny bit after instantiation, disable/enable them. I also tried OnTriggerStay. It works sometimes but mostly not..
    I can't use OverlapSphere because it must take the shape into account exactly.

    Both elements have "IsTrigger" enabled and also have a kinematic RidigBody component attached. It works, when I move them around manually in the editor after instantiation but other than that, OnTriggerEnter/Stay is never called.

    Are there any other possiblities?
    I use Unity 2020.3.20f1.

    Thanks a lot
     
  2. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    446
    How/When are you instantiating those objects? Could you share more details (objects, code, etc)?

    Based on that description, It should work. Making one of those triggers a kinematic rigidbody should be enough.
    See Kinematic Rigidbody Trigger Collider vs Static Trigger Collider and Kinematic Rigidbody Trigger vs Kinematic Rigidbody Trigger)
    https://docs.unity3d.com/Manual/CollidersOverview.html

    I assume that "both" elements are A) the one you instantiated, and B) an object that already exists in the scene(?).
     
  3. stefanob

    stefanob

    Joined:
    Nov 26, 2012
    Posts:
    64
    Actually both elements are B)
    It's a very simple setup. The user can choose objects from a constuction kit and places them next to each other. They never move. I just want to make sure they don't overlap.
    Some of them have primitive colliders, some have a mesh collider (convex).
    And as I said, when I move them a little bit (don't even have to separate them completely), OnTriggerEnter is called.
     
  4. stefanob

    stefanob

    Joined:
    Nov 26, 2012
    Posts:
    64