diff --git a/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnTerrain.cs b/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnTerrain.cs index 8e3e783fe0..c66a62dbea 100644 --- a/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnTerrain.cs +++ b/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnTerrain.cs @@ -50,13 +50,16 @@ namespace OpenRA.Mods.Common.Traits void ITick.Tick(Actor self) { - var loc = self.Location; + var cell = self.Location; + if (!self.World.Map.Contains(cell)) + return; + if (conditionManager == null) return; // The terrain type may change between ticks without the actor moving - var currentTerrain = loc.Layer == 0 ? self.World.Map.GetTerrainInfo(loc).Type : - tileSet[self.World.GetCustomMovementLayers()[loc.Layer].GetTerrainIndex(loc)].Type; + var currentTerrain = cell.Layer == 0 ? self.World.Map.GetTerrainInfo(cell).Type : + tileSet[self.World.GetCustomMovementLayers()[cell.Layer].GetTerrainIndex(cell)].Type; var wantsGranted = info.TerrainTypes.Contains(currentTerrain); if (currentTerrain != cachedTerrain)