Page MenuHomeFeedback Tracker

Add InventoryStorageManagerComponent::GetStorageItemCountByResource()
Closed, ResolvedPublic

Description

Hi would be nice to be able to Get the current items count in a specific storage by ResourceName

Currentrly i'm using this:

//------------------------------------------------------------------------------------------------
static int GetStorageItemCountByResource(IEntity storageEntity, ResourceName resourceName)
{
	int count = 0;
	if(!storageEntity || !resourceName)
		return 0;
	
	array<IEntity> outItems = {};
	ClothNodeStorageComponent clothNode = ClothNodeStorageComponent.Cast(storageEntity.FindComponent(ClothNodeStorageComponent));
	if(clothNode)
	{
		clothNode.GetAll(outItems);
		foreach (IEntity ent0 : outItems)
		{
			count = count + GetStorageItemCountByResource(ent0,resourceName);	
		}
	}
	else
	{
		BaseInventoryStorageComponent storage = BaseInventoryStorageComponent.Cast(storageEntity.FindComponent(BaseInventoryStorageComponent));	
		if(!storage)
			return 0;
		storage.GetAll(outItems);
		foreach (IEntity ent : outItems)
		{
			ResourceName rn = ent.GetPrefabData().GetPrefabName();
			if(rn == resourceName)
				count = count +1;	
		}			
	}				
	
	return count;
}

Details

Severity
Feature
Resolution
Open
Reproducibility
Always
Operating System
Windows 10 x64
Category
General

Event Timeline

Geez changed the task status from New to Assigned.Nov 13 2023, 12:03 PM
Geez closed this task as Resolved.Nov 28 2023, 11:31 AM
Geez claimed this task.
Geez added a subscriber: Geez.

Hello, we have added InventoryStorageManagerComponent::CountItem which works exactly like FindItem. This will be available in the next major update.