Sure, but surely that’s a far less common occurrence than for regular users. Maybe an optional argument in the destroy function would be great for everyone
It can’t be on the destroy function because the event that is being listened to is on this.app, not an Entity.
Ok. You know far more than me of course, but just from and end user point of view I think someway of automatically unsubscribing would be great.
Untested, but you can use a utility function to make this easier for you
eg
function listen(scriptInstance, target, event, callback) {
target.on(event, callback, scriptInstance);
scriptInstance.on('destroy', function() {
target.off(event, callback, scriptInstance);
})
}
// usage in a script
listen(this, app, pc.EVENT_MOUSEDOWN, function() {});
1 Like
Thanks, i tried this, but couldnt get it to work. The main listen function ran and the scriptInstance.on(‘destroy’) but it didnt seem to do the job and I get the same issue as before. I’ll probably just go with the original suggestion:)
Ah okay. I get now. Thanks!