# Issues detecting if position is inside a Polygon2DCollider

I have a Polygon2DCollider set in my scene that I am using Physics2D.OverlapPoint(position, 0) to see if the set position collides with anything. Initially, the collider is stored in memory and then deactivated for future use. When I want to use it I do the following:

targetColliderObj.SetActive(true);

Collider2D collider = Physics2D.OverlapPoint(testPosition, 0);
if (collider == null || collider.tag != targetColliderObj.tag)
{
Debug.Log("Unable to move down a floor.");
}


In the code above I activate the target gameobject for the Polygon2DCollider and check to see if the testPosition is within the collider. The collider is always null even though I am placing the testPosition inside of the collider. Also, I am checking on layer mask 0. The gameobject of the Polygon2DCollider is also on the Default layer (0).

• Have you considered using Collider.OverlapPoint instead, to test only this single object? What do you mean when you say the collider is stored in memory and then deactivated? Depending on the deactivation you're doing, that could mean it's removed from the physics world and no longer visible to Physics2D.OverlapPoint Jan 29 at 0:17
• I'll have to look into trying that. Also, what I mean is they exist in the scene to begin with and are set active. When I setup things in my scene I find the collider, store it in an array, and disable it with SetActive(false). But I enable it again before I check for a collision.
– sabo
Jan 29 at 0:29
• Do you call SyncTransforms so the physics engine is alerted to the newly re-activated collider? Normally changes to the physics world are synched only at specific times in the frame, so if you want it to happen in the middle of your script running you need to ask for it. It sounds though like you just want a collider on a layer that doesn't interact with others, to save the fuss of activating and deactivating it each time you want to check for containment. Jan 29 at 0:32
• I tried setting Auto sync transforms in the project setting and that didn't work. Maybe doing it manually in code is necessary.
– sabo
Jan 29 at 0:37
• I just tried using Collider.OverlapPoint() and it worked. Thanks @DMGregory. If you add an answer I'll accept it.
– sabo
Jan 29 at 1:10

I was able to resolve this issue by using Collider.OverlapPoint(); rather than what I was originally trying. Here is the simple change that was necessary:
targetColliderObj.SetActive(true);