I’m restarting a scene to test some randomisation elements, but getting this error from (I think) a collider instance that’s still trying to process collision between a GameObject
and TileMapTileLayer
instance. It looks like the world
tries to update the collider, even after the Tilelayer has shutdown / been destroyed?
Uncaught TypeError: Cannot read property 'tileWidth' of undefined
at World.collideSpriteVsTilemapLayer (phaser.js?d4ef:126135)
at World.collideHandler (phaser.js?d4ef:125817)
at World.collideObjects (phaser.js?d4ef:125719)
at Collider.update (phaser.js?d4ef:129054)
at World.update (phaser.js?d4ef:124921)
So to restart the scene, I’m invoking the below onPress of a debug key from another Scene. Scrub the old instance of the scene and launch a new one. I even added a custom event to emit just before Scene shutdown - causing me even more confusion!
const worldScene = this.scene.get(WorldScene.KEY);
worldScene.events.emit(WORLD_ACTIONS.PRE_SHUTDOWN);
// ^^ I added this, in case it was a race condition before the WorldScene was shutdown
this.scene.stop(WorldScene.KEY);
this.scene.launch(WorldScene.KEY);
Meanwhile, elsewhere in the code
const collider = scene.physics.add.collider(player, this.groundLayer, (a, b) => {
// Here's the "on collide" code
});
// Even destroying the collider doesn't work?
scene.events.on(WORLD_ACTIONS.PRE_SHUTDOWN, () => {
scene.physics.world.removeCollider(collider);
collider.destroy();
});