private static void DestroyObjects() { List <DestroyCommand> destroyCommands = new List <DestroyCommand>(); destroyCommands.AddRange(pendingDestroyCommands); pendingDestroyCommands.RemoveRange(0, pendingDestroyCommands.Count); foreach (DestroyCommand command in destroyCommands) { if (command == null || !objectsManager.spawnedEntities.ContainsKey(command.id)) { continue; } NetworkEntity toDestroy = objectsManager.spawnedEntities[command.id]; toDestroy.OnNetworkDestroy(command.args); objectsManager.spawnedEntities.Remove(command.id); GameObject.Destroy(toDestroy.gameObject); } }