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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Question How to not get objects to collide but still trigger the OnCollisionEnter method?

Discussion in 'Physics' started by AjaXI, Jan 8, 2023.

  1. AjaXI

    AjaXI

    Joined:
    Sep 13, 2020
    Posts:
    9
    I have managed to get my 2 objects go through each other instead of colliding using layers and the collision matrix, but I would still like for the OnCollisionEnter method to be triggered when they touch or at least an alternative to it that works. Thanks!
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,620
    OnCollisionEnter is there to indicate they have "collided" so what you're asking doesn't make sense. :)

    Typically you would use a trigger for this and use "OnTriggerEnter" so it's unclear why you're not doing that.

    Perhaps you mean you don't want a collision response only and for some reason don't want to use a trigger? If so then use Kinematic Rigidbody for both things coming into contact. Go into the Physics Project Settings and change the "Contacts Pair Mode" to be "Enable Kinematic Pairs".
     
    AjaXI likes this.
  3. AjaXI

    AjaXI

    Joined:
    Sep 13, 2020
    Posts:
    9
    I'm 2 days old in Unity so please bear with me.
    I've coded this into one of the objects that are supposed to go through each other:
    Code (CSharp):
    1.     private void OnTriggerEnter(Collider other)
    2.     {
    3.         Debug.Log("Object touched");
    4.     }
    However, it's not working, the objects do get through each other, but nothing is written in the console.
     
  4. AjaXI

    AjaXI

    Joined:
    Sep 13, 2020
    Posts:
    9
    I've just fixed it!
    Turns out I didn't have to assign layers and mess with the collision matrix at all, I just had to tick the isTrigger Box on both objects. Thank you MelvMay.
     
    MelvMay likes this.