Add an item¶
An item is one Data Asset listed in the item registry. A survivor carries it, uses it, drops it and finds it again after a save. A weapon, a book, a piece of clothing and a food are all items first, so each of them starts with these steps.
Steps¶
- In
Content/ZombieSurvival/DataAssets/Items/Childs/, duplicate the closestDA_Item_*, or create a Data Asset of the classPDA_ItemDef. Name itDA_Item_<Name>. - Fill its fields (table below). Give it a unique
ItemSaveId. - Add it to
DA_ItemRegistry_Default, in the same folder. - Give it a way to be found. On Pine Hollow, and on any map with a
BP_ZoneManager, containers are filled from loot tables, so add it to a loot table. On a small map of your own, add a line to theContentsof a container in the spawn plan. You can also place aBP_ItemPickupin the map, withItemandCountset.
| Field | What it does |
|---|---|
DisplayName |
The name in the inventory row. |
Description |
The tooltip of the row shows the name, then Description, then the state lines of an item that has a state. |
Category |
The item family: Food, Drink, Medical, Tool, Material, Weapon, Ammo, Literature, Furniture or Clothing. |
Weight |
Kilograms, counted against the weight limit of the inventory. |
MaxStack |
How many fit in one slot. 1 for a piece of clothing. |
bConsumable |
Left-clicking the row uses it up. |
HungerRestore, ThirstRestore, FatigueRestore, HealthRestore |
What consuming it gives back. |
WorldMesh |
The static mesh of the item lying on the ground, SM_Item_PillBottle for example. |
WorldMaterial |
The material applied to that mesh. Seven Materials/Items/MI_Item_* instances give one tint per family. |
WorldMaterialSlot |
The material slot of WorldMesh that WorldMaterial replaces. Empty: the first slot. |
Icon |
The Texture2D shown in the inventory row. |
PickupSound |
Played when the item is picked up. Empty: silent. |
WeaponDef |
For a weapon, the PDA_WeaponDef that gives it its numbers. |
BookDef |
For a skill book or a magazine, the PDA_BookDef it is. |
ConditionMax |
For a tool, its condition when new: 25 for the hammer, 20 for the saw, 25 for the screwdriver. Above 0 the item has a state: one row per copy, worn by use, repaired in the Repair category. A weapon takes its own from its WeaponDef. |
ChargeMax |
For a tool that runs on a charge, its full charge: 100 for the blowtorch. |
FurnitureDef |
For a carried piece of furniture, the PDA_FurnitureDef it is set down as. |
ClothingDef |
For a piece of clothing, the PDA_ClothingDef it is worn as. |
ItemSaveId |
The key the save file stores in place of an object reference. It must be unique. |
Other pages fill more fields of the same class: CaliberDef, MagazineDef and AttachmentDef for a
firearm, FoodDef for a food, and MedicineDef
and LightSource in Tune the systems.
A new item needs two pieces of art, a ground mesh and an icon. The shipped icons are in
Textures/Icons/, one texture per item, each rendered from the item's mesh.
One mesh, several items¶
Several items can share one mesh and differ by one part. Five of the six medicines do. Vitamins,
sleeping pills and beta blockers share SM_Item_PillBottle, and antibiotics and antidepressants
share SM_Item_PillBox. Each paints the label slot of its mesh, named M_ItemMedLabel, with its own
MI_ItemMedLabel_<Medicine>. To do the same, name the slot in WorldMaterialSlot and put the item's
own material in WorldMaterial.
From a graph¶
To put an item into the world from a graph, spawn BP_ItemPickup and call
InitFromItem(Item, Count) on it at once. Its BeginPlay runs inside the spawn node, before you can
set Item, so setting the variables alone leaves an invisible pickup.
AC_Inventory.DropStack does this for the items a survivor drops. Three Settings of AC_Inventory
say where the pickup lands. The survivor's own values are on the Inventory component of
BP_Survivor.
| Setting | Default | What it does |
|---|---|---|
DropDistance |
90 | How far in front of its owner the item is dropped. |
DropTraceDepth |
300 | How far down the trace looks for the floor, on the Visibility channel. |
DropPickupClass |
BP_ItemPickup |
The pickup spawned where the trace lands. |
Any floor that blocks Visibility catches dropped items, as the engine's BlockAll and BlockAllDynamic presets do.
Test it¶
- Open
Content/ZombieSurvival/Maps/L_Worldand press Play. - Press T, type
/give <ItemSaveId> [count]and press Enter. The item goes into your bag. - Press Tab. The row shows the icon, the name, the category and the weight. Hover it for the tooltip.
- Drag the row onto the loot window with the ground selected. The item lands on the floor with its
WorldMeshandWorldMaterial. - To check the registry, open
Maps/L_Bootand start it as a Standalone Game (the arrow next to Play), because Esc stops the editor's own Play instead of opening the pause menu. Start a world with NEW GAME, give yourself the item, then Esc, SAVE GAME, MAIN MENU and CONTINUE. The item must still be in the bag.
If it does not work¶
- The item works in play but is gone after a save and load: it is missing from
DA_ItemRegistry_Default. The only sign is a line in the Output Log, Item id '…' read from a save is not in the item registry. - A dropped item hangs in the air: the trace found no floor that blocks Visibility, and the item stays at the height it was dropped from.