How to destroy entities with event.handler?

in my project I’ve got a lot of optional eventListener;

after destroying/enabling the entity someTimes/someTimesNot fetch an event /mouse/touch or most likely keyboard)

as always i made a goood working QuickFix setting a status/mode for everyThing listen to events;

But I’m sure thats verry bat coding :smiley:

In cases like first lockIn I which I:m sure pop up only once , I call element.off(event)

But in other cases I’m not sure to destroy();

I’ve plenty of entitys that are enebaled/disabled that should keep they local values/attributes so I won’ destoy(); them;
But so the enitys are disabled they still listen to events (most likely keyboard) and do something unespected…

every best practice is very welcome…

:cucumber:

I’m not sure what the question is here?

In general, the code that has created the event listener is also responsible for managing whether it should be removed as well.

If you want a script to stop listening to events when an entity is disabled, you will need to remove the event listener when the entity is disabled.

Here’s a post to listen for the disabled/enabled event for the scriptType and entity: Is there an event fired for when an entity is enabled/disabled - #4 by yaustar

1 Like

thats exacrly what I was looking for, stop listening while diabled…

thanx again