Collision with multiple layers not working


does anyone have experience of multiple layer collisions not working with player. Instead the last initialized layer collisions work. All layers are rendered correctly but the problem is with the this.physics.add.collider

Here is the relevant code:

// Create layers from tilemap data 

const groundLayer = map.createLayer('street', darkTileset, 0, 0);
const walls = map.createLayer('trail', darkTileset, 0, 0); //walls layer initialized first and collision not working.
const waterLayer = map.createLayer('water', darkTileset, 0, 0); // waterlayer initialized last and collision works.

map.setCollisionBetween(1, 1000, true, 'walls');
// Set up collision detection for water layer
map.setCollisionBetween(1, 1000, true, 'waterlayer');
// Add colliders for the protagonist with both layers, order doesnt matter here
this.physics.add.collider(this.waterLayer, this.protagonist);
this.physics.add.collider(this.walls, this.protagonist);

This code is used in the create() method. An example where player is able to walk trough obstacles (obstacles are intialized first and hence not working).

Use the setCollisionBetween method of each layer instead.