What is the syntax for declaring a TSortedMap?

I’m creating an inventory for a crafting game and would like to use sorted maps to keep track of item counts. There are blueprinted DataAssets defining the different items available, and each map would use DataAsset pointers as keys with int32s as values that represent the inventory count. There will only be about 5-10 DataAssets per category, and I’d like them to be sorted by item value, so sorted maps seem handy and efficient. I can’t find any examples though of the syntax for declaring a TSortedMap. What’s the ArrayAllocator and how do I define a SortPredicate? Any help would be greatly appreciated.

You can find some examples in Engine Source. Take a look at this

TSortedMap>

There are two params - Allocator and Sort Predicate. The first one is about memory allocation aspects (local stack or heap, circular buffer, etc). The second just give control to sort logic.

Cool, thanks, that did it. It took me a while to get the rest of the code and UI to the point where I could test it but it’s working as intended. Here’s the syntax I found if anyone else runs into this in the future:

struct FBuyableValueLess
{
	FORCEINLINE bool operator()(const UBuyableDataAssetBase* A, const UBuyableDataAssetBase* B) const
	{
		if (A && B)
		{
			return A->GetBaseValue() < B->GetBaseValue();
		}
		return false;
	}
};

// then in your class...
TSortedMap<UThrusterDataAsset*, int32, FDefaultAllocator, FBuyableValueLess> Thrusters;

My UThrusterDataAsset is a subclass of UBuyableDataAssetBase, which inherits from UDataAsset. FDefaultAllocator declares the map on the heap. Another thing is that, unlike TArray, TSortedMap can’t be made a UPROPERTY, so I don’t think it’s garbage collected. At least one of the use cases in the engine code that I found called Empty() on its maps in the class’s destructor. I’m not sure if it’s necessary but I’m planning to call it in BeginDestroy (my inventory is managed by a PlayerState subclass so I’m pretty sure it gets destroyed when loading into another level).