Issues with objects in collider

I have a functionality of creating me NPCs from an object layers inside the create function, which it looks like this:

const npcs = this.physics.add.group();
if (map.getObjectLayer('npcLayer')) {
  map.getObjectLayer('npcLayer')['objects'].forEach(object => {
    const obj = npcs.create(object.x + 8, object.y + 8, 'testNpc');
    obj.properties = object.properties; // assigning properties here
    obj.body.height = object.height;
    obj.body.width = object.width;
    obj.body.immovable = true;
    obj.setSize(14, 12).setOffset(1, 10).setDepth(obj.y);
    // console log here shows them
  });
}
...
this.physics.add.collider(player, npcs, npcAction); // inside the npcAction function they're gone

Like commented in the last line the assigned properties are gone for some reason. How ever I have a same procedure for the loading zones, where this works! The code looks like this:

  const loadingZones = this.physics.add.staticGroup();
  map.getObjectLayer('loadingZoneLayer')['objects'].forEach(object => {
    let xValue = object.x + 8;
    let yValue = object.y + 8;
    let height = object.height;
    let width = object.width;
    switch (object.properties[MapProperties.FACING_IN].value) {
      ...
    }
    const obj = loadingZones.create(xValue, yValue, 'loadingZone');
    obj.properties = object.properties;
    obj.body.height = height;
    obj.body.width = width;
  });
  ...
  this.physics.add.overlap(player, loadingZones, load);

and this works. Inside the load funtion the given object has the assigned properties.

After trying for a day and a half and googleing for answers I’m out of ideas why it’s not working for the npcLayer.

Hi,
Try with:

this.physics.add.collider(player, npcs, (player, npcs) => npcAction(player, npcs),null, this);

Well that works,
now I just want to understand why.

Plus: The player argument in there is not needed, but if I remove it: the properties are gone again.
This makes no sense for me.

I would appreciate if you can explain me this to learn from it.

If a sprite and a group collides, the first argument is always the sprite, this is automatically handled by phaser, i personnaly always put all the arguments and always check what they are, so i’m sure.

ok, thank you for the explanation. I’ll try to remember this :smile: