ItemGeneratorAsset — Generator Barricade Definition
Overview
ItemGeneratorAsset extends ItemBarricadeAsset to define fuel-burning power generators. Generators provide electricity to connected electrical items (lights, sentries, traps) within their wire range. They burn fuel over time, have a fuel capacity, and produce a configurable amount of power.
The class is one of the simplest barricade subclasses at 78 lines. It adds three key properties (capacity, wire range, burn rate) and a 3-byte state array for powered status and remaining fuel.
Source code location: Unturned/Bundles/ItemGeneratorAsset.cs (78 lines), inheriting from ItemBarricadeAsset.cs (605 lines), ItemPlaceableAsset.cs (454 lines), and ItemAsset.cs (base).
Inheritance Chain
ItemAsset → IArmorFalloff
└─ ItemPlaceableAsset
└─ ItemBarricadeAsset
└─ ItemGeneratorAsset — fuel, power, wire rangeClass Definition
csharp
public class ItemGeneratorAsset : ItemBarricadeAsset
{
protected ushort _capacity;
protected float _wirerange;
protected float _burn;
public ushort capacity => _capacity;
public float wirerange => _wirerange;
public float burn => _burn;
public override byte[] getState(EItemOrigin origin) { ... }
public override void BuildDescription(ItemDescriptionBuilder builder, Item itemInstance) { ... }
public override void PopulateAsset(in PopulateAssetParameters p) { ... }
internal override void BuildCargoData(CargoBuilder builder) { ... }
}Core Properties
Fuel Capacity
| .dat Key | Type | Default | Range | Description |
|---|---|---|---|---|
Capacity | ushort | Required | 0–65,535 | Maximum fuel units |
csharp
_capacity = p.data.ParseUInt16("Capacity");Fuel capacity defines how many fuel units the generator can hold. A player fills the generator with fuel items (e.g., gas cans) which each provide a certain number of fuel units.
Burn Rate
| .dat Key | Type | Default | Unit | Description |
|---|---|---|---|---|
Burn | float | Required | Seconds per fuel unit | Time between fuel unit consumption |
csharp
_burn = p.data.ParseFloat("Burn");The burn rate determines how quickly the generator consumes fuel. A value of 2.0 means one fuel unit is consumed every 2 seconds. Lower values = faster consumption.
Fuel consumption rate: fuelPerSecond = 1.0 / burn
| Burn value | Fuel units per second | Fuel units per hour |
|---|---|---|
1.0 | 1.0 | 3,600 |
2.0 | 0.5 | 1,800 |
5.0 | 0.2 | 720 |
10.0 | 0.1 | 360 |
Wire Range
| .dat Key | Type | Default | Unit | Description |
|---|---|---|---|---|
Wirerange | float | Required | Meters | Maximum wire connection distance |
csharp
_wirerange = p.data.ParseFloat("Wirerange");
if (wirerange > PowerTool.MAX_POWER_RANGE + 0.1f)
{
Assets.ReportError(this, "Wirerange is further than the max supported power range of "
+ PowerTool.MAX_POWER_RANGE);
}The wire range defines how far the generator can connect to electrical items. The value is validated against PowerTool.MAX_POWER_RANGE — if the wire range exceeds the engine's maximum supported power range, an error is reported.
State Byte Layout
csharp
public override byte[] getState(EItemOrigin origin)
{
return new byte[3];
}| Byte | Content |
|---|---|
| 0 | Powered state (0 = off, 1 = on) |
| 1–2 | Fuel amount (ushort, little-endian) |
The 3-byte state stores whether the generator is actively producing power and how much fuel remains. The powered state byte allows toggling the generator on/off.
BuildDescription — Inventory Tooltip
csharp
public override void BuildDescription(ItemDescriptionBuilder builder, Item itemInstance)
{
base.BuildDescription(builder, itemInstance);
builder.Append(localization.format("ItemDescription_FuelCapacity", capacity), DescSort_Important);
if (burn > 0.0f)
{
const float SECONDS_PER_HOUR = 3600;
float fuelPerHour = SECONDS_PER_HOUR / burn;
int roundedFuelPerHour = Mathf.RoundToInt(fuelPerHour);
builder.Append(localization.format("ItemDescription_FuelBurnRate", roundedFuelPerHour), DescSort_Important);
float maxRuntimeSeconds = burn * capacity;
float maxRuntimeHours = maxRuntimeSeconds / SECONDS_PER_HOUR;
builder.Append(localization.format("ItemDescription_FuelMaxRuntime", maxRuntimeHours.ToString("0.00")), DescSort_Important);
}
}The tooltip shows three lines:
| Line | Format | Example (capacity=500, burn=2.0) |
|---|---|---|
| Fuel Capacity | 500 | 500 units |
| Fuel Burn Rate | 1800 | Uses 1,800 units per hour |
| Max Runtime | 0.28 | Runs for 0.28 hours (16.7 minutes) |
Calculation:
fuelPerHour = 3600 / burn = 3600 / 2.0 = 1800maxRuntimeHours = (burn * capacity) / 3600 = (2.0 * 500) / 3600 = 0.277...
BuildCargoData — Wiki Export
csharp
CargoDeclaration data = builder.GetOrAddDeclaration("Generator");
data.Append("GUID", GUID);
data.Append("Capacity", capacity);
data.Append("Wirerange", wirerange);
data.Append("Burn", burn);| Column | Source |
|---|---|
GUID | PK, FK to Barricade |
Capacity | _capacity |
Wirerange | _wirerange |
Burn | _burn |
.dat File Reference — Generator-Specific
| .dat Key | Type | Default | Notes |
|---|---|---|---|
Capacity | ushort | Required | Max fuel units |
Wirerange | float | Required | Wire connection range (must be ≤ MAX_POWER_RANGE) |
Burn | float | Required | Seconds per fuel unit consumed |
All ItemBarricadeAsset, ItemPlaceableAsset, and ItemAsset keys are available.
Modding Example — Basic Generator .dat
ini
GUID a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6
Type Barricade
Build Generator
Health 200
Range 4
Radius 0.5
Offset 0.1
Capacity 500
Wirerange 16
Burn 2.0500 fuel capacity, 16m wire range, burns 0.5 fuel/second (30 fuel/minute). Runs for 16.7 minutes on a full tank.
Modding Example — Industrial Generator .dat
ini
GUID f1e2d3c4b5a69788796a5b4c3d2e1f0a
Type Barricade
Build Generator
Health 500
Range 4
Radius 0.8
Offset 0.1
Capacity 2000
Wirerange 32
Burn 5.0
Armor_Tier HighIndustrial generator: 2000 fuel capacity, 32m wire range, burns slowly at 5 sec/unit (0.2 fuel/sec). Full tank lasts 2.78 hours. High armor tier.
Modding Example — Portable Generator .dat
ini
GUID d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9
Type Barricade
Build Generator
Health 100
Range 4
Radius 0.3
Offset 0.05
Capacity 200
Wirerange 8
Burn 1.0
Armor_Tier LowPortable generator: 200 fuel, 8m wire, fast burn (1.0 sec/unit = 1 fuel/sec). Runs for 3.3 minutes. Low armor.
Common Issues
Wire range too large: Wire range must be ≤
PowerTool.MAX_POWER_RANGE. Exceeding this limit creates an asset error. Reduce the wire range or modify the server'sMAX_POWER_RANGEconstant.Fuel not burning: The
Burnfield must be greater than0.0. A value of0would cause division by zero in consumption rate calculations.Capacity overflow:
_capacityisushort(max 65,535). Setting higher values wraps around. Use a spawn table for better fuel items instead of increasing capacity beyond this limit.Runtime calculation confusion:
burnis seconds per unit, not units per second. A largerBurnvalue = slower consumption = longer runtime. This is the inverse of what you might expect.State size: The 3-byte state is fixed — generators always use 3 bytes regardless of capacity or configuration.
Document history
| Version | Date | Author | Notes |
|---|---|---|---|
| 1.0 | 2026-07-28 | 57 Studios | Initial publication. Full generator asset documentation including fuel system, wire range, and modding examples. |
