Uncaught TypeError from phaser-arcade-physics.min.js:1 Uncaught TypeError: Cannot read property 'contains' of undefined

Hey there Phaser forum.

My team and I recently discovered a bug with our game. Once you lose all your lives, you can choose to restart the game from level 1 (scene 1), however, the game gets pretty buggy. To resolve this issue, we stopped using this.scene.switch() to move from scene to scene. Instead, we’re stopping each scene once you leave it due to entering a door or dying, and we’re starting the next scene. This was able to resolve our wacky bugs when starting a new game after dying, however, we’ve ran into a new bug and for some reason it’s only on our level 3.

If you start the game fresh and make it to level 3, as soon as the character collides with the platform it crashes and we get an interesting error which is pasted below. This error was not present when we were going from level 2 to level 3 using the this.scene.switch(level3), so ever since we start using this.scene.start(level3) from level 2 we are seeing this error. Please note the level works just fine if you set it as the first scene of the game, but going from scene 2 to scene 3 bugs out. Any ideas on why this is happening? One thing to note is we’re not using anything in our code with the keyword ‘contains’ per the error.

Error:

Uncaught TypeError: Cannot read property ‘contains’ of undefined
at initialize.contains (phaser-arcade-physics.min.js:1)
at initialize.collideSpriteVsGroup (phaser-arcade-physics.min.js:1)
at initialize.collideHandler (phaser-arcade-physics.min.js:1)
at initialize.collideObjects (phaser-arcade-physics.min.js:1)
at initialize.update (phaser-arcade-physics.min.js:1)
at initialize.update (phaser-arcade-physics.min.js:1)
at initialize.h.emit (phaser-arcade-physics.min.js:1)
at initialize.step (phaser-arcade-physics.min.js:1)
at initialize.update (phaser-arcade-physics.min.js:1)
at initialize.step (phaser-arcade-physics.min.js:1)
phaser-arcade-physics.min.js:1

Here is the code we’re using to go from level 2 to level 3. This is essentially the same code we use to go from one level to another. Basically when the character has the key and touches the doorTrigger it takes u to the next level (which is working fine from level 1 to 2).

level2_scene class:
this.physics.add.overlap(player, doorTrigger, goLevel3, null, this);

main_scene class:
function goLevel3(player, doorTrigger) {
if (hasKey == true) {
this.scene.start(“level3”);
}
}

Again, the level works fine by itself and if we switch the above function from this.scene.start(‘level3’) to switch then it works fine, but using switch caused the previous bug that we had so we’re trying to use start now.

Hello,
I’m having the same error only difference is that I’m using this.scene.restart().
Have you figured out how to fix it?

Exact same issue !! Pls help :c

Using a minified version of Phaser is no use for debugging. Use a standard non-minified build, then you’ll get an actual error you can use and the exact point in the code it was triggered.

I’m using full script since 2 days but same :
image

did any one found a solution to this

:wave:

Post your scene code please.