Let’s say I have some kind of struct like the example below, which I use to keep track of items in my inventory
USTRUCT()
struct ExampleItemStruct{
GENERATED_USTRUCT_BODY()
AActor* myOwner;
int32 itemCount;
float itemValue;
float itemWeight;
}
At the bottom of my inventory panel, I want a little display that displays the total value and weight of everything in my inventory- is there any way I could achieve this by summing structs directly, like this?
ExampleItemStruct sumStruct;
for(int32 i = 0; i < ItemStructList.Num(); i++){
sumStruct+=ItemStructList[i];
}
The obvious alternative would be to manually iterate through every value, and do something like
for(int32 i = 0; i < ItemStructList.Num(); i++){
sumStruct.itemCount+=ItemStructList[i].itemCount;
sumStruct.itemValue+=ItemStructList[i].itemValue;
sumStruct.itemWeight+=ItemStructList[i].itemWeight;
}
But that’s clumsy in comparison, and I don’t want to be wasteful and manually iterate over every field if I don’t have to.