UPROPERTY variables in a standard struct

Will the UPROPERTY TArray below prevent garbage collection of its elements? Or do I need a USTRUCT() for UPROPERTY members to work correctly?

The problem with USTRUCT() is that I cannot create them with template parameters.


template<typename T>
struct FMenuItemList
{
    UPROPERTY(VisibleAnywhere, Category = "Menu")
    TArray<T> ItemList;

    int32 CurrentItem;
};

Nope, won’t work, your struct needs to itself be a UPROPERTY, directly or indirectly, of a UCLASS, since only UObjects are tracked by the reference collector.

Bottom line is, you just can’t mix templates with UE4’s reflection system.