-
Notifications
You must be signed in to change notification settings - Fork 0
ItemUtil
Namespace: ScavLib.util
World-space item utilities. Complements PlayerUtil, which handles items
already in the player's inventory. Use ItemUtil for scanning items in the
world, modifying existing Item instances, and querying the global
ItemInfo registry.
Returns a List<Item> of all items within radius world units of center.
-
includeContained: iftrue, items inside containers are also included. Default isfalse(loose world items only).
Vector2 playerPos = GameUtil.GetPlayerPosition();
List<Item> nearby = ItemUtil.FindNearby(playerPos, 5f);
foreach (var item in nearby)
GameUtil.Log(item.id);Performance note: This calls
Object.FindObjectsOfType<Item>()internally. It is fine for occasional use but avoid calling it every frame over large radii.
Returns the single closest Item to center within maxRadius, or null
if none exist.
Item closest = ItemUtil.FindClosest(GameUtil.GetPlayerPosition(), 10f);
if (closest != null)
GameUtil.Log($"Closest item: {closest.id}");Set an item's durability (0~1) safely. Uses Item.SetCondition() internally,
which correctly drains liquid container contents proportionally. Do not
write item.condition directly — it bypasses liquid container logic.
ItemUtil.SetCondition(myItem, 0.5f); // Set to 50% conditionRestore an item to full condition (1.0).
ItemUtil.Repair(myItem);Toggle an item's favourite flag.
ItemUtil.SetFavourited(myItem, true);Safely remove an item from the world. If the item is inside a container, it
is detached first to keep the container's bookkeeping consistent. The
GameObject is destroyed at end of frame.
ItemUtil.Destroy(myItem);These methods query Item.GlobalItems, the dictionary populated by the game
at startup. They are safe to call at any time after the game has loaded.
| Method | Returns | Description |
|---|---|---|
GetInfo(string id) |
ItemInfo or null
|
Look up an item's definition by ID. |
IsKnownId(string id) |
bool |
Check if an ID exists in the registry. |
GetAllIds() |
IEnumerable<string> |
Enumerate all registered item IDs. |
// Check before spawning
if (ItemUtil.IsKnownId("bandage"))
GameUtil.SpawnAtPlayer("bandage");
// List all registered IDs
foreach (var id in ItemUtil.GetAllIds())
GameUtil.Log(id);