// Building on mouse position private void Build(Vector3 position, Vector2 gridPosition) { SpendResources(); gridSystem.Fill((int)gridPosition.x, (int)gridPosition.y, Cell.Filled); // Rewrite all the shit EntityManager => EntityCommandBuffer (if it could be executed not on the same frame/thread) // This is structural change, so it's somewhat slow if we are building a lot? Entity buildingPrefab = task.buildingPrefab; bool attackable = task.isAttackable; uint durability = task.durability; uint constructionTime = task.constructionTime; // Our new building entity Entity buildingEntity = EntityManager.Instantiate(buildingPrefab); // Cause it's not prefab now EntityManager.RemoveComponent <PrefabTag>(buildingEntity); // Set position EntityManager.SetComponentData <Translation>(buildingEntity, new Translation { Value = (float3)position }); // Add BuildingTag & SelectableTag EntityManager.AddComponent <BuildingTag>(buildingEntity); EntityManager.AddComponent <SelectableTag>(buildingEntity); if (attackable) { SetAttackable(buildingEntity, durability); } // Add BuildingConstructionComponent (inConstruction) EntityManager.AddComponentData <BuildingConstructionComponent>(buildingEntity, new BuildingConstructionComponent { workToComplete = constructionTime }); }