I am working on a Shmup written in Phaser 3. As you might expect, I have lots of different types of enemies, bullets, and effects. For organizational purposes, each type of object has its own group to serve as a pool. Originally, I had set up colliders based on each pool and used metadata to figure out which pools needed colliders with which other pools. This -worked-, but even with a process callback that filtered out inactive objects the colliders running for all of the pooled objects slowed the game down significantly.
To fix this, I created a new phaser group named this.active. Now whenever I spawn an object, I add it to this.active and remove it from this.active group when it is despawned. This.active has a single collider that runs all of the time, with the metadata to sort which objects should and should not collide being applied inside the process callback. This has fixed my performance issues, but it has introduced a separate problem: the only way I know how to introduce a collider on elements of the same group is with:
this.physics.add.overlap(this.active, this.active, HandleOverlap, ProcessOverlap);
The problem with this is that it treats this as two separate groups, i.e. if there are n elements in this.active, it runs n^2 tests. This means each pair of objects is tested twice, and that everything seems to be tested against itself. Is it possible to set up a collider that will treat this as a collider on a single group, i.e. ignores duplicate pairs and runs (n-1)(n)/2 tests? Performance-wise the extra tests are not a huge problem, the bigger issue is that things like weapon damage or power up bonuses are now calculated twice per frame, doubling the effect of everything.
. When using the collision tree I think it’s not simple to detect duplicate pairs. You could write your own loops for this and call