Browse Source

Fixing https://github.com/BabylonJS/Babylon.js/issues/4291

Raanan Weber 7 years ago
parent
commit
789712b67f
1 changed files with 15 additions and 2 deletions
  1. 15 2
      src/Physics/babylon.physicsImpostor.ts

+ 15 - 2
src/Physics/babylon.physicsImpostor.ts

@@ -358,9 +358,22 @@ module BABYLON {
 
         public unregisterOnPhysicsCollide(collideAgainst: PhysicsImpostor | Array<PhysicsImpostor>, func: (collider: PhysicsImpostor, collidedAgainst: PhysicsImpostor | Array<PhysicsImpostor>) => void): void {
             var collidedAgainstList: Array<PhysicsImpostor> = collideAgainst instanceof Array ? <Array<PhysicsImpostor>>collideAgainst : [<PhysicsImpostor>collideAgainst]
-            var index = this._onPhysicsCollideCallbacks.indexOf({ callback: func, otherImpostors: collidedAgainstList });
+            var index = -1;
+            let found = this._onPhysicsCollideCallbacks.some((cbDef, idx) => {
+                if (cbDef.callback === func && cbDef.otherImpostors.length === collidedAgainstList.length) {
+                    // chcek the arrays match
+                    let sameList = cbDef.otherImpostors.every((impostor) => {
+                        return collidedAgainstList.indexOf(impostor) > -1;
+                    });
+                    if (sameList) {
+                        index = idx;
+                    }
+                    return sameList;
+                }
+                return false;
+            });
 
-            if (index > -1) {
+            if (found) {
                 this._onPhysicsCollideCallbacks.splice(index, 1);
             } else {
                 Tools.Warn("Function to remove was not found");