C++
Variables
Readable Structure Arrays
Learn how to display a property as a value for structure arrays.
Tezenari
Oct 12, 2021
Updated 2 years ago
Learn how to display a property as a value for structure arrays.
Tezenari
Oct 12, 2021
Updated 2 years ago
Seeing the number of members in a structure array item isn't overly helpful. Thankfully, when you're dealing with them in C++, there is one easy solution!
When declaring the UPROPERTY for the structure array, you can specify a TitleProperty metadata using the properties from the struct.
For example, using the ItemName property as the TitleProperty will result in the structure displaying that value.
UPROPERTY(EditAnywhere, Meta = (TitleProperty = "ItemName"))
TArray<FItemData> Items;Using multiple structure properties as values can be achieved by surround the property with curly brackets.
UPROPERTY(EditAnywhere, Meta = (TitleProperty = "{ItemName} {ItemQuality}"))
TArray<FItemData> Items;/** The information of the item. */
USTRUCT(BlueprintType)
struct FItemData
{
GENERATED_BODY();
/** The name of the item. */
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FName ItemName;
/** The description of the item. */
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FText ItemDescription;
/** The quality of the item. */
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FText ItemQuality;
//..
};
/** A Data Asset that holds the array */
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
class UInventoryManager : public UActorComponent
{
GENERATED_BODY()
/** The items contained in the inventory. */
UPROPERTY(EditAnywhere, Meta = (TitleProperty = "{ItemName} {ItemQuality}"))
TArray<FItemData> Items;
//..
};