Why does empty if statement fix null reference

Hello, today I was trying to centralize my code and I have run into an interesting problem with even more fascinating solution. So the script which is a grandchild of the script that it is finding returns error:

        NullReferenceException: Object reference not set to an instance of an object

is while trying to debug it I wrote an if statement that checks if the object is not null at the start and the problem was fixed . Here is how the code looks like after deleting the Debug.Log()

    private PlayerControler pControlerSelect;

void Start () {
    pControlerSelect = FindObjectOfType<PlayerControler>();

    if (pControlerSelect != null)
    {
    }

    WeaponSelect();
}

also the error fires from the line that is in method WeaponSelect() and changing the statement to check if the object is null returns the error

No this can’t solve or influence anything. I suspect that you have a wrong if statement when you actually have a null reference exception. You most likely did

if (pControlerSelect = null)

instead of

if (pControlerSelect == null)

The first statement will actually set “pControlerSelect” to null while the second will check if it’s null.