the overlap collider works as intended , however when i try to retrieve the contact points everything returns null. what am i missing? Code (CSharp): ContactFilter2D contactFilter = new ContactFilter2D(); int layer = 12; int layermask = 1 << layer; contactFilter.SetLayerMask(layermask); contactFilter.useLayerMask = true; Collider2D[] colliders = new Collider2D[10]; int FFF = GC.UnitPool[index].MoveRadius.OverlapCollider(contactFilter, colliders); foreach (Collider2D FF in colliders) { if (FF != null) { GC.UnitPool[index].Col.Add(FF); } } //int GetContacts(Collider2D collider, Collider2D[] colliders); ContactPoint2D[] Contact = new ContactPoint2D[10]; int FFFF = GC.UnitPool[index].MoveRadius.GetContacts(contactFilter,Contact); foreach (ContactPoint2D SFS in Contact) { Debug.Log(SFS); Debug.Log(SFS.point); Debug.Log(SFS.collider); Debug.Log(SFS.otherCollider); Instantiate(GOG, SFS.point , Quaternion.identity , GC.UnitPool[index].transform); }
https://docs.unity3d.com/ScriptReference/Collider2D.GetContacts.html Rather than iterating over the entire Contact array, you should only iterate over the number of items GetContacts() actually placed in that array, such as: Code (CSharp): int count = GC.UnitPool[index].MoveRadius.GetContacts(contactFilter,Contact); for(int n=0; n<count; ++n) { var c = Contact[n]; ...
That is useful information, i was confused to why it was cast as a int in the first place, now it makes sense ,. thanks, i wasn't ever able to get the contact points to work. instead i switched to getting the bounds of the collider, and work perfectly for what i intended.