# Issues with objects in collider

**URL:** <https://phaser.discourse.group/t/issues-with-objects-in-collider/6266>\
**Category:** Phaser 3\
**Created:** [May 9, 2020, 6:15pm UTC](https://phaser.discourse.group/t/issues-with-objects-in-collider/6266 "2020-05-09T18:15:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![JMD](https://avatars.discourse-cdn.com/v4/letter/j/f1d935/32.png) [@JMD](https://phaser.discourse.group/u/JMD)\
**Post date:** [May 9, 2020, 6:15pm UTC](https://phaser.discourse.group/t/issues-with-objects-in-collider/6266/1 "2020-05-09T18:15:18Z")

</div>

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

```javascript
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:

```javascript
  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.

---

<div class="post-metadata">

**Author:** ![BlunT76](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/blunt76/32/1454_2.png) [@BlunT76](https://phaser.discourse.group/u/BlunT76)\
**Post date:** [May 9, 2020, 6:49pm UTC](https://phaser.discourse.group/t/issues-with-objects-in-collider/6266/2 "2020-05-09T18:49:57Z")

</div>

Hi,  
Try with:

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

```

---

<div class="post-metadata">

**Author:** ![JMD](https://avatars.discourse-cdn.com/v4/letter/j/f1d935/32.png) [@JMD](https://phaser.discourse.group/u/JMD)\
**Post date:** [May 9, 2020, 6:58pm UTC](https://phaser.discourse.group/t/issues-with-objects-in-collider/6266/3 "2020-05-09T18:58:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![BlunT76](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/blunt76/32/1454_2.png) [@BlunT76](https://phaser.discourse.group/u/BlunT76)\
**Post date:** [May 9, 2020, 7:02pm UTC](https://phaser.discourse.group/t/issues-with-objects-in-collider/6266/4 "2020-05-09T19:02:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![JMD](https://avatars.discourse-cdn.com/v4/letter/j/f1d935/32.png) [@JMD](https://phaser.discourse.group/u/JMD)\
**Post date:** [May 9, 2020, 8:05pm UTC](https://phaser.discourse.group/t/issues-with-objects-in-collider/6266/5 "2020-05-09T20:05:05Z")

</div>

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