Skip to main content

Capacity providers

Most containers hold what their layout says: a list of 9 holds 9, a 6×4 grid holds 24. Some should hold whatever something else says. A backpack can grow with Strength. A shop shelf can hold twice as many facings when it is double-sided. That something is a capacity source.

Setting one​

A capacity source is a field on the layout, Layout → Capacity Source, in the container definition. Pick a source type from the dropdown and fill in its fields. Leave it empty and the layout's own count stands, which is what almost every container wants.

The plugin ships one source: Capacity From Attribute (GAS), in the EDInventoryGAS module. See Gameplay Ability System.

What the answer changes​

The source is asked when the container is built. Its answer resizes the container's layout, so it changes which slots exist, not only the number the container reports:

LayoutWith a source answering N
ListN slots, indices 0 … N-1. 0 means unbounded, as everywhere else.
GridThe width you drew is kept, and the grid gets enough whole rows for N cells, rounding up. 10 cells on a 4-wide grid gives 4×3 = 12. N ≤ 0 keeps the authored board.
SlotNot resized. A paperdoll's slots have names, not a count. The source is ignored, and editor validation and the log both say so.

So, on a list authored at 8 whose source answers 16:

  • an insert at index 10 is accepted;
  • an insert at index 16 is refused with InvalidPlacement;
  • auto-placement searches all 16 slots;
  • Get Max Slots returns 16, and a starter list widget draws 16 slots.

A source can also shrink a container: answer 4 on that same list and index 5 is refused.

The definition asset itself is never modified. Only the container built from it is resized.

Built with this size, kept with this size

Capacity is resolved once, when the container is created. A change to the source afterwards (a Strength buff mid-game, a shelf rotated to double-sided) does not resize a live container. A save also restores the size the container had when it was saved. If capacity has to follow the source during play, recreate the container.

Upgrading from an earlier build

In earlier builds of 1.0.0, a capacity source only changed Get Max Slots. Addressing and auto-placement still used the authored count, so a list authored at 8 refused index 10 even when its source said 16. If you worked around that by authoring the larger count on the layout, you can drop the workaround.

Resolve Slot Count now returns the resized layout's capacity. That is still N for a list. For a grid it is the rounded-up whole rows. For a Slot layout it is the number of named slots, where it used to be the source's raw answer.

When the source cannot answer​

A provider can decline. The GAS source does when the actor has no ability system or no matching attribute set. When it declines, the layout's authored count stands. The container behaves like a fixed one instead of collapsing to zero slots and refusing everything.

Editor validation warns when a definition names a source type that no enabled module provides. A provider that only needs an owner to answer is not flagged. In the editor there is no owner, and that is normal.

Writing your own source (C++)​

A source is two pieces: a data struct the designer picks, and a function that answers it.

// The data. No virtuals: it lives in an FInstancedStruct.
USTRUCT(BlueprintType, meta = (DisplayName = "Shelf Facings"))
struct MYGAME_API FStoreShelfFacingsCapacity : public FEDCapacitySource
{
GENERATED_BODY()

UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Capacity", meta = (ClampMin = "1"))
int32 SlotsPerFacing = 8;
};
// The answer, registered from your module's StartupModule.
FEDCapacityProviderRegistry::Get().Register(FStoreShelfFacingsCapacity::StaticStruct(),
[](const FEDCapacitySource& Source, const AActor* Owner, int32& OutCapacity)
{
const AStoreShelf* Shelf = Cast<AStoreShelf>(Owner);
if (!Shelf)
{
return false; // decline: the authored count stands
}
const auto& Typed = static_cast<const FStoreShelfFacingsCapacity&>(Source);
OutCapacity = Typed.SlotsPerFacing * Shelf->GetFacingCount();
return true;
});

Unregister it in ShutdownModule with FEDCapacityProviderRegistry::Get().Unregister(...).

Return false rather than 0 when you cannot answer. On a list, 0 means unbounded. It does not mean empty.

A custom layout​

If you wrote your own layout and a number can size it, override IEDLayout::ApplyCapacity(Config, Capacity) to resize the config and return true. The default returns false, and then your layout keeps its authored shape with a warning in the log.

Building containers yourself​

UEDContainerComponent and the inventory manager already build containers at the resolved size. If you build a UEDContainer from a definition in your own code, give it Definition->ResolveLayout(Owner, SlotCount) rather than Definition->Layout. Initialise it with the SlotCount that call returns, so the reported capacity and the addressable slots are the same number.