Which mistake could lead to the detection of a non-existing GameObject?

Background info:

I am programming a game with my own “collision system”, that means I don’t use Unity’s inbuilt collision detection, but just check if the positions are identical. I know that that can create problems but my movement is programmed with tiles on integer positions.

Now the real question:

I have an itembox, which depends on which player stands on it. Because of that I check for the “collision” with each player.

If there is a collision it detects that there is some collision, but if I Console.Log the name of the GameObject (with Console.Log(gameObject.name)) it logs “Empty GameObject”, eventhough there is no GameObject named so.

Even weirder is it if I log the position. It began with (0, 0, 0), but every time is stopped and played the game again the z-Position increases in increaments of 1. Now it’s at (0, 0, 48), that is way beyond the game area.

I don’t know how that happens, I do use PlayerPrefs, but I reset all of them every time I play and they shouldn’t even have any influence over this GameObject.

I am not a professional programmer, I do it for fun. I almost certainly don’t use the most efficient code. And my whole code is a big mess.

Check if you modify directly a prefab during the play test.

If you modify an instance of object, when you stop the game, the values go to reset. But if you modify directly a prefab values, you save it and don’t reset.

Pay attention also to what values you save to player pref.