ArrayNum is larger than ArrayMax

Hello.

When I play my game everything works fine for the first 30 seconds, then my inventory stops drawing and a few seconds later I get this error: Screenshot - 6be5584d47622ad604beacf7443026cf - Gyazo

Here’s if you don’t want to look at the screenshot:

inventory	{AllocatorInstance={Data=0x000000416e4825c0 {...} } ArrayNum=20 ArrayMax=22 }	TArray<UItemStruct *,FDefaultAllocator>

this	0x000000416e4b0100 {inventory={AllocatorInstance={Data=0x000000416e4825c0 {...} } ArrayNum=20 ArrayMax=...} ...}	AprojectcrusadeHUD *

Any ideas? I’ve tried null checking everything, but nothing works. :frowning:

You never verify that inventory[x]->slot[y] is valid, that could be your problem.

The other reason could be that for some reason you delete something in your array without removing that element. That would lead to the element in your array pointing at the adress with garbage in it.

OK, I tried this:Screenshot - 7d5778b23820458c56c80e4bb08fb83f - Gyazo

But it gave me the exact same issue.

Your issues sounds to me as if it is related to garbage collection. Especially as you say that it is working fine for some time and it then is going to crash.
To better help you I’d need to know how your array declaration looks like and how and what you add to it (UObject?).
As I see in your screenshots the array is a TArray. A wild guess would be that you didn’t mark it as managed by using UPROPERTY() in the declaration and it contains UObjects which aren’t referenced from somewhere else.

Hope this helps and if not please provide more informations.

Best,
Eckhard

My .cpp file: .cpp - 97812111

My .h file: .h - 631d23c6

If you need the other scripts as well, please tell me. :slight_smile:

EDIT: I fixed it, I think. I moved stuff from my ItemList script which was all static variables and functions without uproperty etc. to my HUD script, and added uproperty to everything.

Make sure your TArray is also using the UPROPERTY() macro, in fact, pretty much every property should have this, otherwise there is a chance this will happen.

Glad to hear that you fixed your issue. For my understanding it was the missing UPROPERTY() so if that’s true, please mark the answer as solution so others know how to fix similiar issues.
Also having something named U…Struct might be misleading as U is the prefix for UObjects and F is the prefix for structs within the engine code base.

Yeah, I marked it as solved. And the struct was because I originally had it as a struct, but decided I wanted a class instead. :slight_smile:

I’ll keep that in mind, thanks. :slight_smile: