fix: unloop and avoid null traits from immediate destroy

This commit is contained in:
cha0s 2019-05-03 08:17:18 -05:00
parent 643f2bbf62
commit c53a3308ee

View File

@ -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);
}