- Home /
 
 
               Question by 
               GiacomInox · Mar 23, 2021 at 02:11 PM · 
                scripting problemcollisionphysics2dcollider2doverlap  
              
 
              How to use OverlapCollider?
I'm creating a vehicle editor where you have a list of parts you can place into the world. After instantiating a part, I want it to immediately destroy itself if it has been placed onto another solid object, so I set up this function:
 public void Place()
     {
         Collider2D coll = GetComponent<Collider2D>();
         ContactFilter2D filter = new ContactFilter2D().NoFilter();
         List<Collider2D> results = new List<Collider2D>();
         if (Physics2D.OverlapCollider(coll,filter,results)>0) Destroy(this);
     }
 
               This, however, doesn't work, and I suspect the probles is with the ContactFilter2D. What am I doing wrong?
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by GiacomInox · Mar 24, 2021 at 01:31 PM
The problem turned out to be Destroy(this). After changing it to Destroy(this.gameObject) it works correctly
Your answer