diff --git a/packages/entity/src/resources/entity-list.js b/packages/entity/src/resources/entity-list.js index c67949b..f102736 100644 --- a/packages/entity/src/resources/entity-list.js +++ b/packages/entity/src/resources/entity-list.js @@ -41,7 +41,9 @@ export default (latus) => { } this.#entities[uuid] = entity; this.#flatEntities.push(entity); - this.#entityTickers.push(entity.tick); + if (entity.hasTickers()) { + this.#entityTickers.push(entity.tick); + } // eslint-disable-next-line no-param-reassign entity.list = this; entity.emit('addedToList'); @@ -176,7 +178,10 @@ export default (latus) => { entity.emit('removedFromList', this); delete this.#entities[uuid]; this.#flatEntities.splice(this.#flatEntities.indexOf(entity), 1); - this.#entityTickers.splice(this.#entityTickers.indexOf(entity.tick), 1); + const index = this.#entityTickers.indexOf(entity.tick); + if (-1 !== index) { + this.#entityTickers.splice(index, 1); + } this.emit('entityRemoved', entity); } diff --git a/packages/entity/src/resources/entity.js b/packages/entity/src/resources/entity.js index 4f3501f..22c73be 100644 --- a/packages/entity/src/resources/entity.js +++ b/packages/entity/src/resources/entity.js @@ -211,6 +211,10 @@ export default (latus) => { this.emit('destroyed'); } + hasTickers() { + return this.#traitTickers.length; + } + invokeHook(hook, ...args) { const results = {}; if (!(hook in this.#hooks)) {