Get a struct array item with only one condition

Hi, I need to check if my struct array has at least one item with the only one condition. I made the functionality like on the screenshot:

Screenshot

But in the “Contains” node I need to input only one condition “Subcategory” and not to check other inputs.

So the question is: How to make something like “Any value” node?

I think you have to do it as

image

would love to know if there’s another way… :slight_smile:

Unfortunately there’s no way (that I know of) of filtering an Array without running through all array items with a loop and checking if a specific property of those items (Rune Name) matches the text your script has access to.
I say “there’s no way (that I know of)” because array objects don’t usually know how to interpret the items that are stored withing them. Some more complex type of object would be capable of doing so (like a Map), but arrays only know information about the array itself, like the number of items, the first and last item, etc.
Now, if you need to specifically filter something out of a collection with a specific value at hand I would consider using DataTables instead of arrays.
DataTables can be built on top of Structs and filtered based on a given key/row name. You could make the row name be the rune name itself and, whenever you need it, just get the whole struct out of the DataTable with the Key/Row Name information that would be equal to your rune name.
There’s this video from Unreal Fest that explains a lot about using DataTables in Unreal but they are very straight forward.
Hope this helps.

Thanks for the answer, but in this case datatables are not suitable for me, because their filling cannot be changed in the game, and I choose runes from my inventory, the content of which can be changed by the player himself, so I use a component with a variable of the array type of structures. It seems that there are no more options, except to iterate over each element of the array.

I made this variant of solution, but I want to print the only one example of each rune in my inventory. So is I will print it on foreach loop - it would printing every rune in my inventory, even if there are duplicates.

1 Like

If you only want one, then you can just break out of the loop :slight_smile:

So the only one solution in this case I can see - to make a temporary array of name type and foreach iteration of my inventory runes - check if TempArray already contains this rune name. If it contains - skip iteration (do nothing), if not - add new rune name to temp array:

After that - just make foreach loop for TempArray for printing rune names.

The goalposts are moving :slight_smile:

Originally, you wanted to check if the struct array contained at least one where Subcategory = x

You could do that in a function, like so

image

In this case I’ll need to input subcategory, but my game contains 200+ subcats =), it will be boring. Make one more foreach loop? Too many loops).

You definitely can do it, I’m just not clear on what is it you’re trying to do…

Where is the list of subcategories?

Sorry, that’s my mistake. I don’t need subcategories, I need rune names. I have four runes in my inventory: Nef, Sha, Aum, Nef. Rune Nef occurs here twice, accordingly, if I display the name of the rune on the screen at each iteration, then I will get the same four runes on the screen. and I need only unique rune names to be displayed, no duplicates. That is, the result should be as follows: Nef, Sha, Aum. In other words, runes with the same names should be combined into one.

Gotcha

image

1 Like

Yep, same solution as mine, but with maps instead of array)

Easier with a map.