Problem with colliders

Hello all,

I have a problem where colliders kicks off before Start() is called and I’m getting a NullReferenceException as the objects aren’t initialized at the time of the collision. The exception is gone when I initialize the objects in Awake().

However, I would still get to the game over scene right after clicking the start button and before any of the objects move and I don’t get any errors in the editor (it’s like the objects are colliding before the game even starts).

I would also like to note that the same code works just fine for other scenes but it gets broken for that specific scene. I’ve tried removing the objects from the scene and building them again but that didn’t help and now I’m not sure what to do :frowning:

I’m using a very simple collision mechanism:

private void OnTriggerEnter2D(Collider2D collision)




Please assist.

Hi Dalia,

In which section and lecture are you?

Can you share some screenshots? What I can get from this code is that something is inside your trigger collider the moment you start the game.

if you want to only want to trigger your game over if something specific hits the trigger collider you’ll have to use the “collision” collider that it being used when OnTriggerEnter2D is being called.