Phaser scene is creating duplicate emit events on each restart

I attach emit events on the scene and listening in another scene

example:

scene 1
this.events.emit(‘add_score’);

scene 2
this.scene1.events.on(‘add_score’, function () {…

Everything is working as should be, but i notice each time when i do scene.restart() emit events will duplicate, i even try scene.stop() and scene.start(), so if i restart scene 20 times emit event that was created will trigger 20 times.

Is this how phaser works? Doesn’t clear emit events so I need to do it manually or I’m facing with some bug from my side?

okay i found solution after digging deeper on the google, phaser doesnt automatically clear up all things from scene so you need manually to do it with this.events.off(‘add_score’);

This happened to me, in your case I used this.scene1.events.once(‘add_score’, function() {…
In this case the “Once”

1 Like