what is the cause of this breakpoint? Currently my array has the size = [100] and returned this error on beginplay… but if I increase the size to = [200] everything works fine.
Ensure condition failed: Lhs.CurrentNum == Lhs.InitialNum [[Source\Runtime\Core\Public\Containers/Array.h] [Line: 216]]
Array has changed during ranged-for iteration!
FDebug::EnsureFailed - 0.000000 s
This is caused by modifying an array during a for each loop for example, you don’t want to add/remove elements during the iteration. What are you trying to do exactly ? if you can post your code I can suggest an alternative way.
Thank you for reply Sir, this is 300 lines of code, looping through all items and if found anything , adding to the array and then from array spawning the item, everything works fine.
the problem starts when I try to randomize the array before spawning items.
Item = Arr[FMath::RandRange(0, Arr.Num() - 1)];
Item is the returning array with contain items to be spawned
Your issue is probably modifying the array and letting the loop continue.
If you’re going to modify the array make sure you exit out of the loop after that using break or return.
I found that I already have a break in this loop where I am modifying the Array if the weapon is added, remove the first row which is not a weapon and add the corresponding ammo type of that weapon.
for (auto& Array : ItemsIDArr)
{
if (Array.Type != EItemType::E_Weapon)
{
ItemsIDArr.RemoveAt(1);
break;
}
}
I’m just saying that shuffle also modify the array so make sure you stop the loop when you do that, similar to add/remove.
if (i == -1)
{
//some code
}
else if (i != -1)
{
//repeat some code
}
if this correct?
Apart from the redundant else if, repeating some code I would probably create a dedicated function for the task, and call it when you want to execute the same code again but maybe with different parameters.