# Can't get overlap event to work on Arcade Physics

**URL:** <https://phaser.discourse.group/t/cant-get-overlap-event-to-work-on-arcade-physics/3514>\
**Category:** Phaser 3\
**Created:** [August 20, 2019, 6:06am UTC](https://phaser.discourse.group/t/cant-get-overlap-event-to-work-on-arcade-physics/3514 "2019-08-20T06:06:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Legomite](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/legomite/32/92_2.png) [@Legomite](https://phaser.discourse.group/u/Legomite)\
**Post date:** [August 20, 2019, 6:06am UTC](https://phaser.discourse.group/t/cant-get-overlap-event-to-work-on-arcade-physics/3514/1 "2019-08-20T06:06:37Z")

</div>

Hi, I’m having difficulty getting the overlap function to work properly. According to the docs, the event emits when at least one of the two has onOverlap set to true. I’ve messed around with a Phaser example to see if I could get it running on there, but it doesn’t seem to be working. Am I doing something wrong?

```
You can basically paste this:
    var config = {
    type: Phaser.AUTO,
    antialias: false,
    width: 800,
    height: 600,
    parent: 'phaser-example',
    physics: {
        default: 'arcade',
        arcade: {debug: true}
    },
    scene: {
        preload: preload,
        create: create,
        update: update
    }
};

var sprite;
var group;

new Phaser.Game(config);

function preload ()
{
    this.load.image('mushroom', 'assets/sprites/mushroom2.png');
    this.load.image('ball', 'assets/sprites/shinyball.png');
}

function create ()
{
    sprite = this.physics.add.image(400, 300, 'mushroom')
        .setVelocity(100, 200)
        .setBounce(1, 1)
        .setCollideWorldBounds(true)
        .setGravityY(200);

    group = this.physics.add.staticGroup({
        key: 'ball',
        frameQuantity: 30
    });

    sprite.body.onOverlap = true;

    Phaser.Actions.PlaceOnRectangle(group.getChildren(), new Phaser.Geom.Rectangle(84, 84, 616, 416));

    group.refresh();

    this.physics.world.on('overlap', function() {alert('hi')}, this);

    //this.physics.add.overlap(sprite, group);
}

function update ()
{
    //sprite.body.debugBodyColor = sprite.body.touching.none ? 0x0099ff : 0xff9900;
}

```

unto this example, [http://labs.phaser.io/edit.html?src=src/physics/arcade/overlap%20collider.js&v=3.19.0](http://labs.phaser.io/edit.html?src=src/physics/arcade/overlap%20collider.js&v=3.19.0)

What’s wrong with the code? Why won’t it alert??

---

<div class="post-metadata">

**Author:** ![Jake.Caron](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/jake.caron/32/1841_2.png) [@Jake.Caron](https://phaser.discourse.group/u/Jake.Caron)\
**Post date:** [August 20, 2019, 1:28pm UTC](https://phaser.discourse.group/t/cant-get-overlap-event-to-work-on-arcade-physics/3514/2 "2019-08-20T13:28:07Z")

</div>

Hey, thanks for providing an example with an easy copy&paste! I am way more apt to help out if there is an easy way to test the issue.

I checked out your example and it seems to work perfectly if you uncomment `this.physics.add.overlap(sprite, group);`

Here is the code with the alert changed to a console log (so the page doesn’t get stuck) and with the above uncommented:

```javascript
 var config = {
    width: 800, height: 600,
    physics: {
        default: 'arcade',
        arcade: {debug: true}
    },
    scene: {
        preload: preload,
        create: create,
    }
};

var sprite, group;

new Phaser.Game(config);

function preload ()
{
    this.load.image('mushroom', 'assets/sprites/mushroom2.png').image('ball', 'assets/sprites/shinyball.png');;
}

function create ()
{
    sprite = this.physics.add.image(400, 300, 'mushroom')
        .setVelocity(100, 200)
        .setBounce(1, 1)
        .setCollideWorldBounds(true)
        .setGravityY(200);

    group = this.physics.add.staticGroup({
        key: 'ball',
        frameQuantity: 30
    });

    sprite.body.onOverlap = true;

    Phaser.Actions.PlaceOnRectangle(group.getChildren(), new Phaser.Geom.Rectangle(84, 84, 616, 416));
    group.refresh();

    this.physics.world.on('overlap', function() {console.log("Hi")}, this);
    this.physics.add.overlap(sprite, group);
}

```

---

<div class="post-metadata">

**Author:** ![Legomite](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/legomite/32/92_2.png) [@Legomite](https://phaser.discourse.group/u/Legomite)\
**Post date:** [August 20, 2019, 4:40pm UTC](https://phaser.discourse.group/t/cant-get-overlap-event-to-work-on-arcade-physics/3514/3 "2019-08-20T16:40:27Z")

</div>

Thanks! I’m not sure why that was not specified in the docs, I thought only enabling onOverlap would do the trick 😄
