diff --git a/packages/entity/index.js b/packages/entity/index.js index 49367f0..0bce52d 100644 --- a/packages/entity/index.js +++ b/packages/entity/index.js @@ -245,7 +245,7 @@ export class Entity extends decorate(Resource) { // Remove instance. delete this._traits[type]; // Unloop. - // instance.entity = undefined; + instance.entity = undefined; } removeTraits(types) { @@ -261,6 +261,11 @@ export class Entity extends decorate(Resource) { tick(elapsed) { for (const type in this._traits) { + // If .destroy is called immediately when ticking a trait, then the next + // traits could go away. + if (!(type in this._traits)) { + continue; + } const instance = this._traits[type]; instance.tick(elapsed); }