Collider2D OnTriggerEnter2D not working, IsTrigger=true and Collider2D IsTrigger=false
Situation
there are two objects. Both have a Collider2d. One with isTrigger = false, the other with isTrigger = true. I added a script for object with isTrigger = true. This script implements OnTriggerEnter2D. This object is implemented to be able to follow the mouse cursor and can be moved over the other object. A kind of selector with range. Its task is to be able to fetch other colliders as active selected.
But OnTriggerEnter2D is not called, but why not?
Does colliders2D with isTrigger = true and other with isTrigger = false cannot see each other?
Example
// is for selector with range - if MouseButton(0) pressed, the player can move it to select BComponent in Range
[RequireComponent(typeof(CircleCollider2D))]
public class AComponent : MonoBehaviour {
// only isTrigger = true here - not pushing
private void Start() { GetComponent<CircleCollider2D>().isTrigger = true; }
// This shall be triggered after the second collider with isTrigger=false collides with the collider attached to this gameObject (isTrigger = true)
private OnTriggerEnter2D(Collider2D collision) { Debug.Log("Enter 2D Trigger"); }
// not implemented here: Object can be moved by pressing MouseLeftButton and move Mouse.
}
// Is for Player Objekt (isTrigger = false) - shall collide with other BComponent
[RequireComponent(typeof(CircleCollider2D))]
public class BComponent : MonoBehaviour {
// only pushing allowed to push other figures away
private void Start() { GetComponent<CircleCollider2D>().isTrigger = false; }
}
Found Solution
My second collider2d gameObject with isTrigger = false must have RigidBody2D.
Your answer
![](https://koobas.hobune.stream/wayback/20220613020838im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
OnCollisionEnter 2d not working 0 Answers
BoxCollider2D OnTriggerEnter2D 1 Answer
void OnTriggerEnter() not working properly? 0 Answers
¿Why wont child move with parent? 0 Answers