Infinite Zone Overlap

Hi Everyone,

I’m trying to write overlaps so that a callback only happens once and doesn’t continue on forever. In one instance, the code works perfectly. In another instance, it doesn’t work at all. The difference seems to be something with zones in different groups overlapping, vs zones in the same group overlapping unless I’m missing something.

Example: This code works as expected - zone_objects and zones are two different groups of zones.

this.physics.add.overlap(this.zone_objects, this.zones, (data, zone) => {;
console.log(‘this callback ran once’)

Example: this code does not work as expected and the callback runs infinitely while the zones are overlapping. zones is, again, just a group of zone objects.

this.physics.add.overlap(this.zones, this.zones, (data_a, data_b) => {;;
console.log(‘this callback loops forever’)

Can anyone help me understand why this is and how I can fix it?

Bonus: please help me learn how to format my code into code blocks, sorry it is just text at the moment.

Hello again, I found the bug. This code works as intended, but I had a variable elsewhere in the code that was turning the zone back on…oops. Sorry for cluttering the forum.