Blueprint Arrays return data when Out-of-Bounds

Hello!

It’s come to my attention that blueprint arrays can be supplied an index that will take them out of bounds. A warning is thrown as expected, but it also has some nasty behavior where it will still return valid data from the array.

Given a five element array of objects, if I attempt to retrieve element #10, it will still return element 5 - this could result in things going horribly wrong using something like complex iteration.

The array needs to return null, not an object, and the game should throw an ‘accessed none’ error much like UnrealScript would, before attempting to continue.

“Given a five element array of objects, if I attempt to retrieve
element #10, it will still return element 5”

I agree with Luke,

This could be so very very confusing in a complex blueprint and really hard to debug, since sometimes element 5 results would be correct… but not if trying to access element 10

I am quite curious, how can blueprints be made to throw exceptions or in some way provide unavoidable feedback to blueprint developers, and stop behavior that would be disastrous in C++ ?

Thank you for UE4!

Rama

Hey Luke,

Thanks for your feedback. We have been unable to reproduce an array returning the last element in the array when attempting to retrieve an element beyond the array’s bounds. Are you using any custom script in your project? If you will provide me with a screenshot of a blueprint with which this issue occurs, I can investigate further.

Best,

Ben Halliday

Hi Ben,

I’m not using anything custom in this. Here’s a sample blueprint setup that I used to demonstrate the issue:

It output the following in the log

LogBlueprintUserMessages: Build Array using For Loop
LogBlueprintUserMessages: Found Item SMBlueprint12 at index 
LogBlueprintUserMessages: Found Item SMBlueprint13 at index 
LogBlueprintUserMessages: Found Item SMBlueprint14 at index 
LogBlueprintUserMessages: Found Item SMBlueprint15 at index 
LogBlueprintUserMessages: Found Item SMBlueprint16 at index 
LogBlueprintUserMessages: Return Array using For Loop
LogBlueprintUserMessages: Found Item SMBlueprint12 at index 0
LogBlueprintUserMessages: Found Item SMBlueprint13 at index 1
LogBlueprintUserMessages: Found Item SMBlueprint14 at index 2
LogBlueprintUserMessages: Found Item SMBlueprint15 at index 3
LogBlueprintUserMessages: Found Item SMBlueprint16 at index 4
LogArray:Warning: Attempted to get an item from array MeshArray1 out of bounds [5/4]!
LogBlueprintUserMessages: Found Item SMBlueprint16 at index 5
LogBlueprintUserMessages: Return Array using For Each
LogBlueprintUserMessages: Appended Item SMBlueprint12 at index 0
LogBlueprintUserMessages: Appended Item SMBlueprint13 at index 1
LogBlueprintUserMessages: Appended Item SMBlueprint14 at index 2
LogBlueprintUserMessages: Appended Item SMBlueprint15 at index 3
LogBlueprintUserMessages: Appended Item SMBlueprint16 at index 4

Hey Luke,

It seems that the ForLoop node is causing the issue you’re experiencing. In all other cases that I’ve tested, a 0 or ‘none’ is returned when asking for an out of bounds index. I’ve entered a report for the inconsistency represented here.

Thanks for the feedback! If you spot any other areas where this happens (in this case it was the ForLoop macro), please let us know and we’ll add it to the report.

Best,

Ben Halliday

It happens but will just give a warning. If you want to reproduce it, try using ArrayLength & not using ArrayLastIndex :slight_smile:

Hello,

Thank you for your report. We were not able to investigate this on the engine version you reported, but there have been many version changes to UE4 since this question was first posted. With a new version of the Engine comes new fixes and it is possible that this issue has changed or may no longer occur. Due to timetable of when this issue was first posted, we are marking this post as resolved for tracking purposes.

If you are still experiencing the issue you reported in the current engine version, then please respond to this message with additional information and we will investigate as soon as possible. If you are experiencing a similar, but different issue at this time, please submit a new report for it.

Thank you.