[Bug][Missing Documentation] BP Array Get and Find have inconsistent failed return values.

Updated:

I think the docs should mention that array FIND function will return a value of -1 if it fails and that GET functions will return a null value if they fail.

I think INT array FIND and GET functions should have a Success BOOL output on the node since a NULL return is not distinguishable from a valid return if the array contains values of “-1”

Thanks to ScottSpadea for helping me properly define my issue!

Cheers,

  • ook

<<<<<<<<<<< ORIGINAL POST

Heya, I was wondering what array nodes like “Find” and “Get” would return when these functions failed and was sad to discover that this wasn’t in the documentation. So I set up a test case to find out the answers and was further sad to discover they don’t both return -1 which is confusing.

IMO:

  1. They should both return -1 when they fail.
  2. They should throw a warning to the log so you can identify bad code.
  3. The return values should be documented: Array Nodes | Unreal Engine Documentation

For benefit of those who come across this:

  1. A failed Array Get Returns: 0
  2. A failed Array Find Returns: -1

Cheers,

  • ook

i disagree with all of your points.

  1. you claim they should both return -1 when they fail, but Array::Get does not return an index, it returns the element of the array, which can be of any type, and is usually not a number.

  2. you claim they should throw a warning to the log, but failing to find an item in an array does not mean anything is wrong with the code. i don’t want a log warning me every time my player tries to open a door, but the door does not find the door key in the player’s inventory.

  3. the return values for a template function cannot be documented, because they can be any class. you can expect that it returns either the default value for that type or that it returns null.

  1. I agree. I was only looking at it from the perspective of INT arrays. Good point.

  2. I can see this side of the argument. But I would like to have the option to know if my GET failed because it tried to access a part of the array that doesn’t exist without having to build a test for it every time. For FIND I guess it’s reasonable to simply check ISVALID after the get. Perhaps an improvement would be a success, BOOL output on GET and FIND nodes? (perhaps only on INT arrays since this is the only case where the result is ambiguous)

  3. Actually the FIND in array does always return an INT which is the index to that objects position in the array. So I disagree with you on this point. You can document this. For GET I think you could also document that it will return NULL if it fails. Obvious for real programmers but not for beginners and such.

i agree, the Find documentation should mention the -1 result, and the Get documentation should mention returning the default value of out of bounds indices.

the bool output on Get nodes could probably help a bit, but until something like that exists, you should usually compare the length of the array to the index you are trying to access, before you access it.