I would really appreciate an explanation or answer to this question as to why my blueprint code is running the way that it is. Specifically, I have a loop with the last index set to 155, I was using the last index of an array to set this so it can be dynamically used for different sized sets, however I was getting an error because the loop was running on index 156. It is inconsistent, sometimes it will run only to index 154, other times it will run to index 155, sometimes it runs to index 156.
Please watch this video showing this in action, let me know if there is any more information that you need, or anything that you can find as to why this might be happening. It really does seem like this is a bug to me, because I can’t think of a reason why a loop ever should run past the last index.
Link to video:
I have searched online to see if anyone had similar issues, but can only find other topics regarding loops. Please let me know what I am doing wrong!
Pass-By will modify a variable whenever the function is run. Your loop runs to 155, but because you’ve plugged Index into the Pass-By it will increment it and any time you print Index, that increment is held even if the loop processed the int at a different value.
In my loop, every single time it runs, Index is being incremented and when Index is called to Print it prints the incremented value NOT the value the For Loop ran.
Both my loop and your loop are still processing the Index values correctly (your loop only goes to Index = 155) but the value of Index in anything past the loop is determined by the Increment function.
EDIT: Edited the two Loop images to remove a useless Branch that I had in there.
Thank you so much for this, I was extremely confused as to why this would be happening. Capturing the index in a local variable prior to incrementing the index and incrementing that variable instead of the index seems to have resolved this issue. Thank you again!