OpenRA/OpenRA · error · MapGenerationException

BuildingWeights.* must be >= 0

Error message

BuildingWeights.* must be >= 0

What it means

Thrown when any value in the BuildingWeights dictionary is negative. BuildingWeights maps civilian building actor/obstacle keys to integer selection weights; a negative weight is invalid for the weighted-random placement. The '*' in the message denotes 'any key'.

Source

Thrown at OpenRA.Mods.Common/Traits/World/ClassicMapGenerator.cs:408

				if (MinimumBuildings > MaximumBuildings)
					throw new MapGenerationException("MinimumBuildings must be <= maximumBuildings");
				if (CivilianBuildings < 0 || CivilianBuildings > FractionMax)
					throw new MapGenerationException($"CivilianBuildings must be between 0 and {FractionMax} inclusive");
				if (CivilianBuildingDensity < 0 || CivilianBuildingDensity > FractionMax)
					throw new MapGenerationException($"CivilianBuildingDensity must be between 0 and {FractionMax} inclusive");
				if (MinimumCivilianBuildingDensity < 0 || MinimumCivilianBuildingDensity > FractionMax)
					throw new MapGenerationException($"MinimumCivilianBuildingDensity must be between 0 and {FractionMax} inclusive");
				if (CivilianBuildingDensityRadius < 0)
					throw new MapGenerationException("CivilianBuildingDensityRadius must be >= 0");
				if (ResourcesPerPlayer < 0)
					throw new MapGenerationException("ResourcesPerPlayer must be >= 0");
				if (OreUniformity < 0)
					throw new MapGenerationException("OreUniformity must be >= 0");
				if (OreClumpiness < 0)
					throw new MapGenerationException("OreClumpiness must be >= 0");
				foreach (var kv in BuildingWeights)
					if (kv.Value < 0)
						throw new MapGenerationException("BuildingWeights.* must be >= 0");
				foreach (var kv in ResourceSpawnWeights)
					if (kv.Value < 0)
						throw new MapGenerationException("ResourceSpawnWeights.* must be >= 0");
				foreach (var kv in ResourceSpawnWeights)
					if (!ResourceSpawnSeeds.ContainsKey(kv.Key))
						throw new MapGenerationException($"ResourceSpawnSeeds does not contain possible resource spawn `{kv.Key}`");

				if (!(terrainInfo.Templates.TryGetValue(LandTile, out var landTemplate) && landTemplate.Contains(0)))
					throw new MapGenerationException("LandTile is not valid");
				if (!(terrainInfo.Templates.TryGetValue(LandTile, out var waterTemplate) && waterTemplate.Contains(0)))
					throw new MapGenerationException("WaterTile is not valid");

				if (Players > 32)
					throw new MapGenerationException("Total number of players must not exceed 32");

				var symmetryCount = Symmetry.RotateAndMirrorProjectionCount(Rotations, Mirror);
				if (Players % symmetryCount != 0)
					throw new MapGenerationException($"Total number of players must be a multiple of {symmetryCount}");

View on GitHub (pinned to a520984d91)

Solutions

  1. Set every BuildingWeights entry to 0 or a positive integer (use 0 to effectively exclude a building).
  2. Remove entries you do not want rather than negating them.

Example fix

# before
BuildingWeights:
  HOUSE: 10
  TOWER: -2
# after
BuildingWeights:
  HOUSE: 10
  TOWER: 0
Defensive patterns

Strategy: validation

Validate before calling

foreach (var kv in param.BuildingWeights)
    if (kv.Value < 0)
        throw new InvalidOperationException($"BuildingWeights[{kv.Key}] must be >= 0");

Type guard

static bool BuildingWeightsOk(ClassicMapGeneratorInfo.Parameters p) => p.BuildingWeights.All(kv => kv.Value >= 0);

Try / catch

try { mapGenerator.Generate(modData, args); }
catch (MapGenerationException ex) when (ex.Message.Contains("BuildingWeights.*"))
{ /* set every weight to 0 or positive; 0 excludes a building */ }

Prevention

When it happens

Trigger: Map generation with a BuildingWeights yaml sub-node containing an entry whose integer value is negative, e.g. 'BuildingWeights: { Tower: -2 }'.

Common situations: Hand-editing the weights to suppress a building and using a negative number instead of 0; or a stray minus sign in the yaml.

Related errors


AI-assisted analysis of OpenRA/OpenRA@a520984d91 (2026-08-13). Data as JSON: /api/errors/24b72e7cad55c784. Report an issue: GitHub.