Just a comment: Instead of iterating the array to find an item and adding it, if it is not present already, you can also use the AddUnique function of (T)Array.
This only adds the item, if it is not yet present and returns its index, and in case it is already there, it returns index_none.
I believe, this can make your life much easier, both, in bp as well as the c++ function.
And, as to the out of range - the root cause of this is most likely hidden somewhere in your RandomItemType function. Need to have a look at this, I found, that you did post this one and that the out of bound is goneâŚ
Whatâs in the RandomItemNumber C++ function (Random Number Item in BP) ? Is it just a random int in range?
follow few steps:
1, how you are restricting the duplicates? by number, by location, by name etc⌠?
if by number, check if you have duplicate numbers already in the array
if by location, check if you have duplicate locations stored in the array
if by name, check if you have duplicate names in the array
any of them you have twice, your loop will generate duplicate of it and it will be re-stared as infinite loop.
I am restricting the duplicates on locations stored in the data table of 6 rows, and 6 portions of random item groups are generated on this bases.
I donât have any duplicated location in these rows, so why is the loop is infinite while it should not be?
While looking at the code, I think, the Shuffle in your BP/C++ is not needed, as you already use a random index to read a value, so the shuffle just randomizes an array, from which you plan to read at a random location, thus only creating overhead.
It could simply be a memory/ram issue, and unable to complete the number of iterations required⌠test with 2 rows, 2 item types . . . and check if it solved the infinite loop
Remember if the engine is freezing its mean the loop is still infinite.
try one more thing, clearing the array each time the group of items is generated, test and update us about the results
if (ItemsTypeArr.Find(LocItemType) == -1) //check for duplicates
{
ItemsTypeArr.Add(LocItemType); // add all items to array if not duplicated
ItemsTypeArr.Empty();
}
nah, not that way⌠fix few errors in your code to make the array be able to clear properly.
1: your loop should have a body and you should call RandomItemType(LocItemType); in this loop, if you call outside of this loop, it makes loop useless.
2: this should be called under the for loop , in step one I explained.