diff --git a/src/core/game/GameView.ts b/src/core/game/GameView.ts index e79922c7c..c62c4b5ad 100644 --- a/src/core/game/GameView.ts +++ b/src/core/game/GameView.ts @@ -223,6 +223,8 @@ export class GameView implements GameMap { private defensePostGrid: DefenseGrid; + private toDelete = new Set(); + constructor( public worker: WorkerClient, private _config: Config, @@ -244,6 +246,9 @@ export class GameView implements GameMap { } public update(gu: GameUpdateViewData) { + this.toDelete.forEach((id) => this._units.delete(id)); + this.toDelete.clear(); + this.lastUpdate = gu; this.updatedTiles = []; @@ -283,6 +288,10 @@ export class GameView implements GameMap { this.defensePostGrid.removeDefense(unit); } } + if (!unit.isActive()) { + // Wait until next tick to delete the unit. + this.toDelete.add(unit.id()); + } }); }