# Phaser 3: Collider Issue - error after scene reloads

**URL:** <https://phaser.discourse.group/t/phaser-3-collider-issue-error-after-scene-reloads/5619>\
**Category:** Phaser 3\
**Created:** [March 23, 2020, 3:35pm UTC](https://phaser.discourse.group/t/phaser-3-collider-issue-error-after-scene-reloads/5619 "2020-03-23T15:35:03Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Benstrocity](https://avatars.discourse-cdn.com/v4/letter/b/a4c791/32.png) [@Benstrocity](https://phaser.discourse.group/u/Benstrocity)\
**Post date:** [March 23, 2020, 3:35pm UTC](https://phaser.discourse.group/t/phaser-3-collider-issue-error-after-scene-reloads/5619/1 "2020-03-23T15:35:03Z")

</div>

Hello everyone, I’m having a bug I can’t seem to squash. Short and simple, I have spikes in my game, when the player collides with the spikes, after 2 seconds, the scene will reload. That is working. After the scene reloads, when I collide with the spikes again, I get an error. It shows to be an error in the phaser.min.js file. Below is a GIF I created to show what happens:

 ![spike bug](https://global.discourse-cdn.com/free1/uploads/phaser1/original/2X/2/255985928546976a4daa2cc6f9ea8868c0dadf9a.gif)

I have a Fail Class that specifies what happens when a player fails on a hazard/obstacle. I created a class so that I can have one chunk of code to re-use regardless of what kind of death the player experiences.

Here is the code for the Fail constructor:

```
export default class Fail {

    constructor(scene, level) {
        this.scene = scene;

        this.promptFail = () => {
            this.failText = scene.add.text(this.scene.width / 2, this.scene.height / 2, level, {fill: "white", fontSize: "75px", fontFamily: "pixel1"});
            this.scene.scene.start(this.scene);
            console.log("Restart level");
        }
        scene.time.delayedCall(2000, this.promptFail, null, scene); // timer that removes the notify text after 4 seconds
    }
}

```

Here is the code in my level that implements the Fail constructor:

```
this.physics.add.collider(this.player.player, this.spikes, this.fail, null, this);

fail() {
        this.fail = new Fail(this, "level1");
    }
```

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [March 23, 2020, 4:07pm UTC](https://phaser.discourse.group/t/phaser-3-collider-issue-error-after-scene-reloads/5619/2 "2020-03-23T16:07:39Z")

</div>

I’m not sure but you may need to change that to

```javascript
this.fail = new Fail(this, "level1");

this.physics.add.collider(this.player.player, this.spikes, this.fail, null, this);

```

---

<div class="post-metadata">

**Author:** ![Benstrocity](https://avatars.discourse-cdn.com/v4/letter/b/a4c791/32.png) [@Benstrocity](https://phaser.discourse.group/u/Benstrocity)\
**Post date:** [March 23, 2020, 4:12pm UTC](https://phaser.discourse.group/t/phaser-3-collider-issue-error-after-scene-reloads/5619/3 "2020-03-23T16:12:12Z")

</div>

Thanks for the quick response. So I attempted that and got rid of the `fail()` method entirely.

Now I get the error immediately on the first collision with the spikes. Wonder if it has something to do with having a separate class/constructor?

```
phaser.min.js:1 Uncaught TypeError: i.call is not a function
    at initialize.collideSpriteVsGroup (phaser.min.js:1)
    at initialize.collideHandler (phaser.min.js:1)
    at initialize.collideObjects (phaser.min.js:1)
    at initialize.update (phaser.min.js:1)
    at initialize.step (phaser.min.js:1)
    at initialize.update (phaser.min.js:1)
    at initialize.h.emit (phaser.min.js:1)
    at initialize.step (phaser.min.js:1)
    at initialize.update (phaser.min.js:1)
    at initialize.step (phaser.min.js:1)
```

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [March 23, 2020, 4:27pm UTC](https://phaser.discourse.group/t/phaser-3-collider-issue-error-after-scene-reloads/5619/4 "2020-03-23T16:27:38Z")

</div>

I take that back, do this instead:

```javascript
this.physics.add.collider(
  this.player.player,
  this.spikes,
  function () {
    this.fail = new Fail(this, "level1");
  },
  null,
  this
);

```

---

<div class="post-metadata">

**Author:** ![Benstrocity](https://avatars.discourse-cdn.com/v4/letter/b/a4c791/32.png) [@Benstrocity](https://phaser.discourse.group/u/Benstrocity)\
**Post date:** [March 23, 2020, 4:32pm UTC](https://phaser.discourse.group/t/phaser-3-collider-issue-error-after-scene-reloads/5619/5 "2020-03-23T16:32:32Z")

</div>

That did it! Thanks @samme

Do you happen to know why the way I had it was causing issues? I’m not sure I understand that error stack.

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [March 23, 2020, 6:12pm UTC](https://phaser.discourse.group/t/phaser-3-collider-issue-error-after-scene-reloads/5619/6 "2020-03-23T18:12:08Z")

</div>

Somehow `this.fail` was defined during the first scene run but undefined after restart. But regardless, you wouldn’t want to use `this.fail` (a Fail instance) as a collision callback; instead you would instantiate a new Fail in the callback.

If you switch to _phaser.js_ then the traces will be a little easier to read.

---

<div class="post-metadata">

**Author:** ![Benstrocity](https://avatars.discourse-cdn.com/v4/letter/b/a4c791/32.png) [@Benstrocity](https://phaser.discourse.group/u/Benstrocity)\
**Post date:** [March 24, 2020, 6:23pm UTC](https://phaser.discourse.group/t/phaser-3-collider-issue-error-after-scene-reloads/5619/7 "2020-03-24T18:23:02Z")

</div>

I need to do that. I’m afraid if I change to phaser.js everything will break. Have you had any experience switching from one to the other?

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [March 24, 2020, 6:33pm UTC](https://phaser.discourse.group/t/phaser-3-collider-issue-error-after-scene-reloads/5619/8 "2020-03-24T18:33:07Z")

</div>

It shouldn’t break if both are the same Phaser version. Here is v3.17.0:

[https://www.jsdelivr.com/package/npm/phaser?version=3.17.0&path=dist](https://www.jsdelivr.com/package/npm/phaser?version=3.17.0&path=dist)

---

<div class="post-metadata">

**Author:** ![Benstrocity](https://avatars.discourse-cdn.com/v4/letter/b/a4c791/32.png) [@Benstrocity](https://phaser.discourse.group/u/Benstrocity)\
**Post date:** [March 24, 2020, 7:37pm UTC](https://phaser.discourse.group/t/phaser-3-collider-issue-error-after-scene-reloads/5619/9 "2020-03-24T19:37:01Z")

</div>

Thanks I’ll try it out.
