Detect a collision but allow prefabs to pass through each other

Hey all! How can I detect if two prefabs are colliding/intersecting while allowing them to pass through each other if the two prefabs both require Rigidbodies and circle colliders? Thanks!

Set “IsTrigger” on the colliders.

Then have a script with OnTriggerEnter2D/OnTriggerExit2D

Check the “IsTrigger” button in the inspector on your collider component.

Your tag suggests it’s a 2D game… so:

  void OnTriggerEnter2D(Collider2D other) {
        if (other.gameObject.tag == "YourTag") {
           Debug.Log("Its a hit!");
        }
  }

but!, for 3D:

      void OnTriggerEnter(Collider other) {
            if (other.gameObject.tag == "YourTag") {
               Debug.Log("Its a hit!");
            }
      }

and if you want to check whether is has left the trigger change “Enter” to “Exit”!

Good Luck!