Hello, I have some trouble with Scene Switch, I found the problem when I try to change the scene that has orbit camera script, it doesn’t work. (Im used script: switch full scene example)
This my projects:
https://playcanvas.com/editor/scene/1490821
your event listener is alive
this.on(“destroy”, ()=> {
this.app.off(“your every event”)
})
1 Like
There’s a nice pattern that @jpaulo introduced to me which I really like and makes setting/unsetting events easier:
// initialize code called once per entity
WeaponProjectile.prototype.initialize = function() {
this.setEvents('on');
this.on('destroy', () => this.setEvents('off'));
};
WeaponProjectile.prototype.setEvents = function(offOn) {
this.entity[offOn]('triggerdown', this._onTriggerDown, this);
this.entity[offOn]('triggerup', this._onTriggerUp, this);
};
It saves code duplication of event names and calls, reducing potential issues and typos.
4 Likes
Thanks yautsar, i will try