Issue with infinite loop

I am working on setting up the logic for generating a weapon with random perks.

I have a data struct that holds the info for the weapon.

The base weapon data is chosen randomly from a data table and stored in the struct.

From there I need to generate four random perks for the weapon. The perks are chosen randomly from a data table the same as the weapon.

The dilemma that I have is I need to be able to check the category of the perk, and if it is the default value of ‘None’ then I need get another random perk.

Every different way I have tried this I end up getting and infinite loop error.

I have attached an image of a stripped down version of what I was trying and this is causing the error.

You could create a local array of type Weapon Perks (within your Get Random Weapon Perk function) with all Perk types, but without the none entry. When you want to select perks, just select a random array element and then get the data table entry associated with that perk type.

If you don’t want repeats, then you can do that as well by removing selected entries from this array, so that it is not available for next random selection.

Thank you.

I managed to fix the infinite loop issue in the end. I had added the default ‘None’ option to the Enum for the data table and it had changed the value for all entries to none. As such it was always returning none therefore getting stuck in the loop.

Your way does sound a bit more efficient than mine however so will look at implementing that.