How to generate every possible GameObject Combination from several Lists
So this seems straightforward but I;m having trouble wrapping my head around the code. I assume it would involve permutations and hash sets, but I just can't crack it.
SO: I have an NPC randomization system, which uses 15 Male variations, and 15 Female variations. On top of that, I have maybe 200-300 possible clothing pieces that can randomly be selected at runtime, and then combined into a single Skinned Mesh.
However, generating LODs at runtime is giving me major lag spikes for each NPC, so Ii've decided i need to randomize and then Generate LODs for them at in the Editor, and then load the random "LOD Meshes" into the skinned renderers instead at runtime.
Right now i can manually "randomize" them with a custom Inspector function, and that works fine, but i don't want to just do that over and over and over, possibly hundreds of times (15 x 15 x 200+ etc) So my question is, is there a way I could possibly run a function that takes all my Lists of "Shirts" "Pants" "Boots" etc as well as "MaleBodies" and "FemaleBodies" of GameObjects, and gets EVERY POSSIBLE combination, and adds them to a new List or HashSet that I can then go down the line and iterate through?
Basically I just want to make sure I generate LODs for every single possible NPC combination, and I don't wanna sit there and spend like 2 days hitting "Randomize" and "GenerateLOD", only to accidentally get some of the same combinations without noticing. I'd like to fill a new List with each combination, using some kind of serialized class like this:
public List<RandomCombination> NewRandomNPCVariations;
[System.Serializable]
public class RandomCombination
{
public GameObject BodyMesh;
public GameObject HeadMesh;
public GameObject ShirtMesh;
public GameObject PantsMesh;
public GameObject BootsMesh;
}
and then I can just right a custom inspector button to Cycle through them and generate LODs. Anyone have any idea how i might go about this?
I manually fill the Lists in the script currently, so I have a List already of "AllShirtObjects", "AllPantsObjects", and "AllBodyObjects" etc. I'd like to get every combination of THOSE lists, and send them to the above "RandomCombination" class variables, and then fill the NEW List with all those RandomCombinations, etc.
Your answer
![](https://koobas.hobune.stream/wayback/20220613060846im_/https://answers.unity.com/themes/thub/images/avi.jpg)