Collision null when entity destroyed , so listener cant be 'offed'

Hi - I would like to switch these listeners off when the scene this entity is changed - but the collision is null when the entity is destroyed, so I can’t without causing an error.

I’m not removing it elsewhere, so where would it have gone ? - the below is the init. Do collisions get whacked first before the entity is destroyed ?

        this.entity.collision.on('triggerenter', this._onTriggerEnter, this);

        this.entity.collision.on('triggerleave', this._onTriggerLeave, this);


        this.on('destroy', function () {

            console.log("Destroying"+this.entity.name);

            console.log("collider is "+this.entity.collision+"<");

            if(this.entity.collision)

            {

            this.entity.collision.off('triggerenter', this._onTriggerEnter, this);

            this.entity.collision.off('triggerleave', this._onTriggerLeave, this);

            }

        }, this);

ok thanks for any assistance :slight_smile:

I’m not sure if there’s a defined order where the components are removed when an entity is destroyed, so you may want to listen to the entity destroy event instead.