Skip to main content

Retain & Release

These functions manage the keep-alive ref-count that prevents loaded assets from being garbage collected. See Keep-Alive for the full explanation.

Retain Assets

Increment the ref-count for each asset. If an asset is already in memory, the handle is created immediately (synchronous, no hitch). If not, it is loaded synchronously in the background.

Category: AsyncKit | Retain

PinTypeDescription
World Context ObjectUObject*Any in-world object (auto-filled)
AssetsTArray<TSoftObjectPtr<UObject>>Assets to retain
tip

Call Retain Assets from On Loaded if you want to immediately protect the just-loaded assets without reloading them. The subsystem detects they are already in memory.

Release Assets

Decrement the ref-count. When any asset's count reaches zero, its internal handle is released and the GC is free to collect it.

Category: AsyncKit | Retain

PinTypeDescription
World Context ObjectUObject*Any in-world object
AssetsTArray<TSoftObjectPtr<UObject>>Assets to release

Release All Retained

Drop all retained assets immediately, resetting all ref-counts to zero.

Category: AsyncKit | Retain

Use this on level transitions or when closing a major game state to ensure no stale assets linger.

Example: loading screen pattern

OnBeginLoadingScreen:
Load Assets With Progress
On Progress ──▶ Update loading bar
On Loaded ──▶ Retain Assets [all loaded]
──▶ Hide loading screen

OnEndPlay / OnLevelUnload:
Release All Retained