Hi! I have “n” instanced static meshes and I have to set the static meshes of the instances using elements from a static meshes array… The problem is that I need to get all the available combinations of array elements considering the “n” variable values… For example:
I have 3 elements in the array (0,1, 2)
If n = 3
The possible combinations should be:
0, 0, 0;
0, 0, 1;
0, 0, 2;
0, 1, 0;
0, 1, 1;
and so on…
Do you know what’s the better way to achieve all the combinations of elements?
Let me know and thanks in advance!
Ok, as i thought… Thank you anyway!
Maybe re-think your approach, that’s basically N! which is bad news in any language…
Just for fun, I implemented a solution but only for 3 elements. For more elements, I would recommend to use a recursive function and C++, but nothing stops you of just adding as many loops as necessary in this one.
It’s a function that takes an array of 3 elements and outputs an array of strings containing all the combinations. In this case, 27 combinations. However it’s quite easy to change the input and output types. I only use these ones because yes.
Function:
Usage:
Result:
I’m replaying this post just because I tried to do like you recommended me and I wrote a C++ recursive function that print out all combinations of the elements of an array… Then I wanted to try to rebuild the same function via blueprint to see if it was possible, and I did it. So I decided to share this function as it could be useful for someone else.
The main problem of doing this via BP is that you can’t make an array of arrays so I did it using an array of structurs and each structure contains an array of int. Is important to save the array of structures variable out of the function so it will be only updated and not overwrited.
Function
Usage
Output
I hope it will helps someone in future, good evening!
1 Like
Thank you for this, is it possible to do it with a structure of arrays?