Why does my code ignore a true if-condition?
<p>I've got the following code:</p>

<pre><code>    private static void checkCodesInPlayerCenter(GameObject player)
    {
        Vector2 collisionCenter = player.GetCollisionCenter(player.PublicCollisionRectangle);

        if (TileMap.GetMapSquareAtPixel(collisionCenter) == null)
        {
            return;
        }

        for (int i = 0; i &lt; TileMap.GetMapSquareAtPixel(collisionCenter).Codes.Count; ++i )
</code></pre>

<p>It is possible that sometimes the object I get from GetMapSquareAtPixel is null. To not cause a NullReferenceException in the for-loop I decided to check is its null, and if so end the function early, however it seems to completely ignore the if-condition, even if the object returned is null.
I've set a breakpoint on the return statement but the code never goes there and instead triggers the NullReferenceException I tried to avoid.</p>

<p>Any help please? </p>
