Skip to main content

Item Stack View

Properties

Item stack views hold constant, weak references to item stacks. Here are the main differences between item stack views and item stacks:

  • The item stack being referenced can't be modified.
  • The item stack being referenced can't be deposited elsewhere.
  • The reference is weak; the item stack object may be garbage collected if it's not referenced elsewhere.
  • If the item stack object is garbage collected, the view may become invalidated (IsValid -> false and IsEmpty -> true)
  • The item stack view is not persistent (it can't be saved/loaded in view form).
  • Item stack views can reference more or fewer items than the stack contains.

Purpose

Item stack views are used primarily by Can functions to return an item stack that you may read but not change. Some situations also use them for 'what if' scenarios: e.g., suppose we're asking whether we can withdraw items from an inventory. The inventory has 2 items in its slot, but we can only withdraw 1. The inventory would return an view with an item count of 1 (with just an item stack, this wouldn't be possible).