From 5cd5cadf79ca4d840e5f731ab9a7ab4efecf858f Mon Sep 17 00:00:00 2001 From: samme Date: Sun, 3 Dec 2023 16:14:46 -0800 Subject: [PATCH] Fix removing destroyed Container child --- src/gameobjects/container/Container.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/gameobjects/container/Container.js b/src/gameobjects/container/Container.js index 78e58f30e..e86e495ef 100644 --- a/src/gameobjects/container/Container.js +++ b/src/gameobjects/container/Container.js @@ -438,7 +438,7 @@ var Container = new Class({ */ addHandler: function (gameObject) { - gameObject.once(Events.DESTROY, this.remove, this); + gameObject.once(Events.DESTROY, this.onChildDestroyed, this); if (this.exclusive) { @@ -976,7 +976,7 @@ var Container = new Class({ { if (list[i] && list[i].scene) { - list[i].off(Events.DESTROY, this.remove, this); + list[i].off(Events.DESTROY, this.onChildDestroyed, this); list[i].destroy(); } @@ -1452,6 +1452,25 @@ var Container = new Class({ this.tempTransformMatrix.destroy(); this.list = []; + }, + + /** + * Internal handler, called when a child is destroyed. + * + * @method Phaser.GameObjects.Container#onChildDestroyed + * @protected + * @since 3.70.1 + */ + onChildDestroyed: function (gameObject) + { + ArrayUtils.Remove(this.list, gameObject); + + if (this.exclusive) + { + gameObject.parentContainer = null; + + gameObject.removedFromScene(); + } } });