Skip to content

ItemUtil

QinShenYu edited this page Jun 10, 2026 · 2 revisions

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.


World Scanning

FindNearby(Vector2 center, float radius, bool includeContained = false)

Returns a List<Item> of all items within radius world units of center.

  • includeContained: if true, items inside containers are also included. Default is false (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.

FindClosest(Vector2 center, float maxRadius = float.MaxValue, bool includeContained = false)

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}");

Instance Manipulation

SetCondition(Item item, float condition)

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% condition

Repair(Item item)

Restore an item to full condition (1.0).

ItemUtil.Repair(myItem);

SetFavourited(Item item, bool favourited)

Toggle an item's favourite flag.

ItemUtil.SetFavourited(myItem, true);

Destroy(Item item)

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);

Global Registry Queries

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);

Clone this wiki locally