Why is the if statement failed? C++

I see the random integer from 0 to 99 however you can’t guarantee that the array has a valid index, for this I would suggest doing something like to ensure the index is valid:
ItemType = Arr[FMath::RandRange(0, Arr.Num() - 1)];

This will limit the random integer to within range and should fix your out of bound issue.

Edit: changed my example to be similar to your Arr array.

1 Like