# Array index 0 bug

**URL:** <https://forums.unrealengine.com/t/array-index-0-bug/459771>\
**Category:** Character & Animation\
**Tags:** UE4-24, array-nodes, broken, bug, unreal-engine, question\
**Created:** [December 21, 2019, 6:53am UTC](https://forums.unrealengine.com/t/array-index-0-bug/459771 "2019-12-21T06:53:54Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Slimwaffle](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/slimwaffle/32/696460_2.png) [@Slimwaffle](https://forums.unrealengine.com/u/Slimwaffle)\
**Post date:** [December 21, 2019, 6:53am UTC](https://forums.unrealengine.com/t/array-index-0-bug/459771/1 "2019-12-21T06:53:54Z")

</div>

Since upgrading to 4.24.1 all blueprint nodes that get an array(eg Get all widgets of class) throw a warning message similar to this;  
Attempted to access index 0 from array ‘CallFunc\_GetQueryResultsAsLocations\_ResultLocations’ of length 0 in {fileName}

Adding is valid nodes will just make the error throw twice. Once for the is valid and once for the Get.  
In previous versions of the engine I don’t get this.  
Please guys how can I fix this? I don’t know what to do because all my code uses valid checks before trying to do anything.

---

<div class="post-metadata">

**Author:** ![CodingRook](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@CodingRook](https://forums.unrealengine.com/u/CodingRook)\
**Post date:** [December 21, 2019, 10:54am UTC](https://forums.unrealengine.com/t/array-index-0-bug/459771/2 "2019-12-21T10:54:52Z")

</div>

First of all… sometimes it does help to actually open a copy of your project in the new versions rather than convert in place (I plead guilty of being lazy myself and just converting in place). Anyway, hopefully you haven’t lost an older working copy that could be useful for troubleshooting, perhaps you just upgraded from 4.24 to 4.24.1 which doesn’t require converting.

So, you mentioned a {filename}, do you mean there is something going on in your C++ code as well (if any?). Could this perhaps be a deprecated function issue… something you are using that is not supported by 4.24 anymore?

Since it would be hard to believe that arrays stopped working in the new version, I’ll say it has something to do in particular with your arrays. As mentioned above it depends on what elements you’re feeding into them and how you obtained them, check if any dependencies or anything very esoteric you’ve done has changed with the new version.

Maybe a screenshot or two, a bit more detail in general, might help people understand where your problem is.

---

<div class="post-metadata">

**Author:** ![Slimwaffle](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/slimwaffle/32/696460_2.png) [@Slimwaffle](https://forums.unrealengine.com/u/Slimwaffle)\
**Post date:** [December 21, 2019, 12:29pm UTC](https://forums.unrealengine.com/t/array-index-0-bug/459771/3 "2019-12-21T12:29:56Z")

</div>

Here is just one example. But every single time I have used an array or a switch I get warning errors. Some I have been able to fix using valid checks. Others I haven’t been able too. What is weird is all the code works and does its job but just throws these errors.

 ![294285-piccy.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/a/2/6a29d99ff0982175bff39c5761a825457f775a14.jpeg)

 ![294286-piccy-2.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/d/2/ed2e8549a5ad9682c6e1eed11c056630fd33c608.jpeg)

---

<div class="post-metadata">

**Author:** ![CodingRook](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@CodingRook](https://forums.unrealengine.com/u/CodingRook)\
**Post date:** [December 21, 2019, 1:48pm UTC](https://forums.unrealengine.com/t/array-index-0-bug/459771/4 "2019-12-21T13:48:06Z")

</div>

Hmmm… in your example above, it just means that the owner Pawn (which I assume it returns as Valid and your Branch executes just fine afterwards - I just can’t see because the picture cuts off) does not have any components of that class. You have to trace this back and make sure it still happens.  
Why do you need to get an array of them with GetComponentsByClass()? Why not just get the one you need? Do you have multiple ones on same character? Perhaps because they all inherit from a base one? Can’t tell what BP\_BehaviorComponent is, but if it doesn’t have any children classes, then I personally don’t understand why you need to find an array of them.

---

<div class="post-metadata">

**Author:** ![Slimwaffle](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/slimwaffle/32/696460_2.png) [@Slimwaffle](https://forums.unrealengine.com/u/Slimwaffle)\
**Post date:** [December 21, 2019, 1:56pm UTC](https://forums.unrealengine.com/t/array-index-0-bug/459771/5 "2019-12-21T13:56:56Z")

</div>

I was able to fix this with a valid check. And I fixed all my arrays be using get valid index before get a copy at the index I want.  
I’m still having a ton of trouble with enums and switchs. Because you can’t check if an enum state is valid.  
In that particular screenshot yeah its an AI that inherits from a base one and they have multiple components.

---

<div class="post-metadata">

**Author:** ![CodingRook](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@CodingRook](https://forums.unrealengine.com/u/CodingRook)\
**Post date:** [December 21, 2019, 3:36pm UTC](https://forums.unrealengine.com/t/array-index-0-bug/459771/6 "2019-12-21T15:36:50Z")

</div>

So it sounds like a design issue. You may have to rethink how you implement your stuff so that you don’t have to check like that all the time.  
And yes, when you try to find by “class” where that “class” is a base with multiple children classes, probably best to check for nullptr or that you actually have the derived class you need before trying to access any elements in the return array.  
Did you ever figure out though why all this was working in the earlier UE4 version as you said…?

---

<div class="post-metadata">

**Author:** ![Slimwaffle](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/slimwaffle/32/696460_2.png) [@Slimwaffle](https://forums.unrealengine.com/u/Slimwaffle)\
**Post date:** [December 21, 2019, 11:17pm UTC](https://forums.unrealengine.com/t/array-index-0-bug/459771/7 "2019-12-21T23:17:09Z")

</div>

I’m not sure how but I want to vote that last response as the answer.  
I’m not sure why everything was fine but then didn’t work correctly in the newest version.  
But I kind of like it this way. It teaches me to validate stuff before calling it. I just wish you could validate enum states before using them for something like a switch.

---

<div class="post-metadata">

**Author:** ![TYN522](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TYN522](https://forums.unrealengine.com/u/TYN522)\
**Post date:** [May 15, 2023, 7:11am UTC](https://forums.unrealengine.com/t/array-index-0-bug/459771/8 "2023-05-15T07:11:18Z")

</div>

the problem is that the functon GET (an elment in array) is propagate. it mean that some times (but always in my app) it’ll be always calls and there isn’t a way to stop it. usaualy it lead Access violation and crash app then. i’m a little angry to developers because it have left 4 years since without any progress.
