UFUNCTION() inside USTRUCT()

Is it possible? I’m currently trying to create custom structures that I can use for an inventory system. This is an attempt at not having to spawn an actor in the world for every object that requires one and so that I can keep the inventory as a data structure.

Here are the examples of what I’m trying to do:

USTRUCT(BlueprintType)
struct FItemStack {
    GENERATED_USTRUCT_BODY()

    AActor * item;
    float stack;

    FItemStack() {}
    FItemStack(AActor * add_item, float add_stack) {
	    item = add_item;
	    stack = add_stack;
    }
};

USTRUCT(BlueprintType)
struct FInventory {
    GENERATED_USTRUCT_BODY()

    TArray<FItemStack> Items;
    int32 total_space;

        // UFUNCTION HERE
    int32 getMaxSlots() { return total_space; }
    void setMaxSlots(int32 slots) { total_space = slots; }

    FItemStack & getItemAtIndex(int32 index) { return Items[index]; }

    int32 addItemToInventory(AActor * add_item, float add_stack) {
	    Items.Add(FItemStack(add_item, add_stack));
    }
    void removeItemFromInventory(AActor * remove_item, float remove_stack) {

    }

    FInventory() {}
};

Reflection system does not support struct functions, you can use them in C++, but if you want to use it in blueprint you will need to create static functions that will interact with there structures.

There also no need to be afraid of spawning inventory as a actor, as long as you won’t have any scene or primitive component it won’t effect performance. If calling SpawnActor is annoying for you then maybe consider creating inventory component ;]

My god you’re a genius, why did I not think of an Inventory component. You sir, are a hero.