TArray of Struct editor crash

Hi,
I’m trying to make a TArray of a Struct it compiles in visual studio but the editor crushes.
This is my .h file:

USTRUCT()
struct FInvItem
{
	GENERATED_BODY()
		uint32 stasts = 0;
};

class AtptestCharacter : public ACharacter
{
	GENERATED_BODY()
	// here is the auto generated stuff

	TArray<FInvItem, TFixedAllocator<7>> Equipment;
}

.cpp

Equipment[0].stasts;

I don’t see my mistake and I hope you could help me.

Thanks a lot for every tipp : )

What is the error you get?

Are you reading from index 0 when there is nothing in the array? (This will make it crash)

Thak you for your awnser, I didn’t fill the Array, but I don’t know how to fill it could you show me, how fill it with a default object?

Simply add an object of the struct. array.add(object)

thanks but how do I create a default object?

Hey 143258-

Based on the code provided, IGorilla is correct in that you are trying to access an element of your array that doesn’t exist. After declaring the array, you have to add elements to it (with Equipment.Add([ItemToAdd]) ). Something to note, the “ItemToAdd” has to be of the type that the TArray accepts (in this case ItemToAdd has to be an FInvItem). For example, you could add an FInvItem InventoryWeapon to your .h file, then in the .cpp you would use Equipment.Add(InventoryWeapon). Hope this helps.

Cheers

Thank you a lot it works : )))
I’m lucky that there are smart guys in this forum.