TFunction - passing reference to a function - cant get it to work

I am currently working on getting this too work.

I want to pass callback functions to an UAsyncLoader along with the request using a FDataObject, and in the callback I want to include the thing that was loaded. I will also be potentially having multiple of these so callbacks for after the AsyncLoad() would be beneficial.

one place I intend to use these is in my inventory system so that I don’t have dozens to hundreds of unique blueprints floating in memory

for this I have an FItemDef think of this a just a USTRUCT these work as expected

USTRUCT(BlueprintType)
struct FItemDef
{
    int32 ItemID = 0;
};

then I have an inventory UInventoryComp : public ActorComponent that is each going to be calling my UAsyncLoader : public UGameInstanceSubsystem which is responsible for the AsyncLoading calls to AssetManager, and keeping track of when these can be released. the Loaded item for this will be

UCLASS()
ASpawnableItem : public AActor`
{
// ...
public:
    FItemDef ItemDef;
// ...
};

Items will be spawned through a combinations of DataTables, and TSoftClassPtr<> these are working fine.

the Inventory has the function to be invoked after the load

UFUNCTION()
void ReceiveAsyncLoadedItem(ASpawnableItem* LoadedItem);

the AsyncLoader is supposed to have a function

// "this is where I get the error."
// UFUNCTION()
void LoadItemAsync(const FItemDef& itemToSpawn, TFunction<void(ASpawnableItem*)>& Callback);

the error VS throws is

Error : Unable to find 'class', 'delegate', 'enum', or 'struct' with name 'TFunction'

I even went so far as to try and #include "Templates/Function.h" which does not satisfy VS

1 Like