# FStreamableManager Question

**URL:** <https://forums.unrealengine.com/t/fstreamablemanager-question/2360640>\
**Category:** C++\
**Tags:** data-asset, unreal-engine, question\
**Created:** [February 26, 2025, 7:22pm UTC](https://forums.unrealengine.com/t/fstreamablemanager-question/2360640 "2025-02-26T19:22:41Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![blAddddDe](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@blAddddDe](https://forums.unrealengine.com/u/blAddddDe)\
**Post date:** [February 26, 2025, 7:22pm UTC](https://forums.unrealengine.com/t/fstreamablemanager-question/2360640/1 "2025-02-26T19:22:42Z")

</div>

I have PrimaryDataAsset:

```C++
class ODWIRKSRPG_API UItemDataAsset : public UPrimaryDataAsset
{
	GENERATED_BODY()

public:
        UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "UI", meta=(AssetBundles="UI"))
	TSoftObjectPtr<UTexture2D> ItemIcon;
...
};

```

and in the inventory component, I implement the method:

```C++
void UInventoryComponentBase::GetAllItemsInCategory(TEnumAsByte<EItemCategory> Category, bool& bSuccess,
	TArray<FPrimaryAssetId>& ItemIDs)
{
	UAssetManager& AssetManager = UAssetManager::Get();
	for (const FInventorySlot& Slot: Items)
	{
		const FPrimaryAssetId& ItemID = Slot.ItemId;

		FStreamableManager& StreamableManager = UAssetManager::Get().GetStreamableManager();

		TSharedPtr<FStreamableHandle> Handle = StreamableManager.RequestSyncLoad(
			{AssetManager.GetPrimaryAssetPath(ItemID)}
		);
		
		if (Handle.IsValid() && Handle->HasLoadCompleted())
		{
			if (UItemDataAsset* Item = Cast<UItemDataAsset>(Handle->GetLoadedAsset()))
			{
				if (Item->ItemCategory == Category)
				{	
					ItemIDs.Add(ItemID);
				}
			}
			Handle->ReleaseHandle();
		}
		
		bSuccess = !ItemIDs.IsEmpty();
	}
}

```

QUESTION: when I use the StreamableManager.RequestSyncLoad method, does it load the bandles as well or are they left unloaded?

_if there are any tips on how to improve the method/code they are welcome_

Thx.

---

<div class="post-metadata">

**Author:** ![MagForceSeven](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/magforceseven/32/906563_2.png) [@MagForceSeven](https://forums.unrealengine.com/u/MagForceSeven)\
**Post date:** [February 26, 2025, 7:35pm UTC](https://forums.unrealengine.com/t/fstreamablemanager-question/2360640/2 "2025-02-26T19:35:17Z")

</div>

> [@blAddddDe](#):
>
> does it load the bandles as well or are they left unloaded?

Bundles default to unloaded and loading through the StreamableManager will not change any bundle states.

You can call:

1. `UAssetManager.LoadPrimaryAsset/LoadPrimaryAssets/LoadPrimaryAssetsWithType` (which take a list of bundles to load along with the asset)
2. `UAssetManager.PreloadPrimaryAssets` (also takes a list of bundles)
3. `UAssetManager.ChangeBundleStateForPrimaryAssets/ChangeBundleStateForMatchingPrimaryAssets` (which can load or unload bundles on an already loaded primary asset).

These are all async operations that don’t have synchronous versions. (but you can use the handle’s `WaitUntilComplete` function to make it synchronous on your own)  
`PreloadPrimaryAssets` works similar to the call you’re already making to the StreamableManager, where the assets are keep alive through references and the stream handle. The three other `LoadPrimaryAsset` functions keep the assets loaded through the AssetManager itself and they will remain loaded until you call `UnloadPrimaryAsset/UnloadPrimaryAssets/UnloadPrimaryAssetsWithType`.

---

<div class="post-metadata">

**Author:** ![blAddddDe](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@blAddddDe](https://forums.unrealengine.com/u/blAddddDe)\
**Post date:** [February 26, 2025, 8:20pm UTC](https://forums.unrealengine.com/t/fstreamablemanager-question/2360640/3 "2025-02-26T20:20:57Z")

</div>

Thanks for the reply, I’m the opposite, I don’t need to load the bundles

---

<div class="post-metadata">

**Author:** ![MagForceSeven](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/magforceseven/32/906563_2.png) [@MagForceSeven](https://forums.unrealengine.com/u/MagForceSeven)\
**Post date:** [February 26, 2025, 8:31pm UTC](https://forums.unrealengine.com/t/fstreamablemanager-question/2360640/4 "2025-02-26T20:31:36Z")

</div>

Cool beans.

> [@blAddddDe](#):
>
> if there are any tips on how to improve the method/code they are welcome

A couple things:

1. Don’t use TEnumAsByte. Declare your enum as an `enum class` instead.
2. You get the AssetManager before the loop, but then you get it every iteration to get the StreamableManager.
3. Frankly this is a terrifying function. Either you should make 1 load request for all the elements you want, then loop over them. Or cache the category on the slot so that you can limit the assets you load to only the ones you actually need (and not just to check that member). Or just keep the asset loaded all the time (the expensive stuff is behind bundles anyway).
4. You shouldn’t need to manually release the stream handle. That’ll release when it goes out of scope (the loop iteration, or the function body if you were to take my #3 to heart).

---

<div class="post-metadata">

**Author:** ![blAddddDe](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@blAddddDe](https://forums.unrealengine.com/u/blAddddDe)\
**Post date:** [February 27, 2025, 2:09pm UTC](https://forums.unrealengine.com/t/fstreamablemanager-question/2360640/5 "2025-02-27T14:09:56Z")

</div>

WOW, thanks for the comments, I didn’t even notice that I was getting a StreamableManager every iteration.

---

<div class="post-metadata">

**Author:** ![blAddddDe](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@blAddddDe](https://forums.unrealengine.com/u/blAddddDe)\
**Post date:** [February 27, 2025, 6:06pm UTC](https://forums.unrealengine.com/t/fstreamablemanager-question/2360640/6 "2025-02-27T18:06:34Z")

</div>

> [@MagForceSeven](#):
>
> Frankly this is a terrifying function. Either you should make 1 load request for all the elements you want, then loop over them. Or cache the category on the slot so that you can limit the assets you load to only the ones you actually need (and not just to check that member). Or just keep the asset loaded all the time (the expensive stuff is behind bundles anyway).

```C++
void UInventoryComponentBase::GetAllItemsInCategory(TEnumAsByte<EItemCategory> Category, bool& bSuccess,
	TArray<FPrimaryAssetId>& ItemIDs)
{
	UAssetManager& AssetManager = UAssetManager::Get();
	TArray<FSoftObjectPath> PrimaryAssetsSoftObjectPaths;
	for (const FPrimaryAssetId& PrimaryAssetId : GetPrimaryAssetIds())
	{
		PrimaryAssetsSoftObjectPaths.Add(AssetManager.GetPrimaryAssetPath(PrimaryAssetId));
	}
	
	FStreamableManager& StreamableManager = UAssetManager::Get().GetStreamableManager();
	TSharedPtr<FStreamableHandle> Handle = StreamableManager.RequestSyncLoad(PrimaryAssetsSoftObjectPaths);
	if (Handle.IsValid() && Handle->HasLoadCompleted())
	{
		TArray<UObject*> LoadedAssets;
		Handle->GetLoadedAssets(LoadedAssets);

		for (UObject* const& LoadedAsset : LoadedAssets)
		{
			if (UItemDataAsset* Item = Cast<UItemDataAsset>(LoadedAsset))
			{
				if (Item->ItemCategory == Category)
				{
					ItemIDs.Add(Item->GetPrimaryAssetId());
				}
			}
		}

		Handle->ReleaseHandle();
	}
	
	bSuccess = !ItemIDs.IsEmpty();
}

```

What about this option?

---

<div class="post-metadata">

**Author:** ![MagForceSeven](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/magforceseven/32/906563_2.png) [@MagForceSeven](https://forums.unrealengine.com/u/MagForceSeven)\
**Post date:** [February 27, 2025, 7:39pm UTC](https://forums.unrealengine.com/t/fstreamablemanager-question/2360640/7 "2025-02-27T19:39:48Z")

</div>

It’s not something I’d like to see in one of my projects, but it’s probably fine for you and yours right now.

---

<div class="post-metadata">

**Author:** ![blAddddDe](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@blAddddDe](https://forums.unrealengine.com/u/blAddddDe)\
**Post date:** [February 27, 2025, 7:49pm UTC](https://forums.unrealengine.com/t/fstreamablemanager-question/2360640/8 "2025-02-27T19:49:39Z")

</div>

Thank you for your feedback

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [March 29, 2025, 7:49pm UTC](https://forums.unrealengine.com/t/fstreamablemanager-question/2360640/9 "2025-03-29T19:49:48Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
